@@ -2882,31 +2882,18 @@ export class AppImportExportService {
28822882 organizationId : string ,
28832883 branchId ?: string
28842884 ) : Promise < void > {
2885- // Resolve target branch: use explicit branchId, or fall back to default branch
2886- let targetBranchId = branchId ;
2887- if ( ! targetBranchId ) {
2888- const defaultBranch = await manager . findOne ( WorkspaceBranch , {
2889- where : { organizationId, isDefault : true } ,
2890- select : [ 'id' ] ,
2891- } ) ;
2892- if ( ! defaultBranch ) return ;
2893- targetBranchId = defaultBranch . id ;
2894- }
2895-
2896- // Check if a branch-specific DSV already exists
2897- const existingBranchDsv = await manager . findOne ( DataSourceVersion , {
2898- where : { dataSourceId : dataSource . id , branchId : targetBranchId } ,
2899- } ) ;
2900- if ( existingBranchDsv ) return ;
2901-
2902- // Find the default DSV to copy from
2903- // const defaultDsv = await manager.findOne(DataSourceVersion, {
2904- // where: { dataSourceId: dataSource.id, isDefault: true },
2905- // });
2885+ // Ensure the default DSV first — independent of any git branch. The default
2886+ // DSV (is_default=true, branch_id=null) is the data source's canonical version
2887+ // and must exist for every real data source. Dummy / optionless data sources
2888+ // skip the options-driven DSV creation in the import loop (gated on
2889+ // `importingDataSource.options`), and a non-git workspace has no branch to
2890+ // trigger the branch path below — so without ensuring it here the DS ends up
2891+ // with zero DSVs (queries bound, but the DS unusable on the data source page).
2892+ // Find-or-create keeps it idempotent: option-bearing DSes already created their
2893+ // default DSV upstream and just match here.
29062894 let defaultDsv = await manager . findOne ( DataSourceVersion , {
29072895 where : { dataSourceId : dataSource . id , isDefault : true } ,
29082896 } ) ;
2909- // if (!defaultDsv) return;
29102897 if ( ! defaultDsv ) {
29112898 defaultDsv = await manager . save (
29122899 manager . create ( DataSourceVersion , {
@@ -2935,6 +2922,25 @@ export class AppImportExportService {
29352922 }
29362923 }
29372924
2925+ // Resolve target branch for the branch-specific DSV: use explicit branchId, or
2926+ // fall back to the default branch. Non-git workspaces have no branches — the
2927+ // default DSV ensured above is all that's needed, so stop here.
2928+ let targetBranchId = branchId ;
2929+ if ( ! targetBranchId ) {
2930+ const defaultBranch = await manager . findOne ( WorkspaceBranch , {
2931+ where : { organizationId, isDefault : true } ,
2932+ select : [ 'id' ] ,
2933+ } ) ;
2934+ if ( ! defaultBranch ) return ;
2935+ targetBranchId = defaultBranch . id ;
2936+ }
2937+
2938+ // Check if a branch-specific DSV already exists
2939+ const existingBranchDsv = await manager . findOne ( DataSourceVersion , {
2940+ where : { dataSourceId : dataSource . id , branchId : targetBranchId } ,
2941+ } ) ;
2942+ if ( existingBranchDsv ) return ;
2943+
29382944 // Create branch-specific DSV
29392945 const branchDsv = await manager . save (
29402946 manager . create ( DataSourceVersion , {
0 commit comments