44using System . Linq ;
55using SpocR . Managers ;
66using SpocR . Models ;
7+ using SpocRVNext . Configuration ; // for EnvConfiguration
78
89namespace SpocR . Services ;
910
@@ -108,11 +109,37 @@ public IReadOnlyList<SchemaModel> GetSchemas()
108109
109110 // Load current config (best-effort) to derive IgnoredSchemas dynamically; if unavailable fallback to snapshot status field.
110111 List < string > ignored = null ; SchemaStatusEnum defaultStatus = SchemaStatusEnum . Build ;
112+ List < string > buildSchemas = null ; // SPOCR_BUILD_SCHEMAS positive allow-list
111113 try
112114 {
113115 var cfg = _configFile ? . Config ; // FileManager keeps last loaded config
114116 ignored = cfg ? . Project ? . IgnoredSchemas ?? new List < string > ( ) ;
115117 defaultStatus = cfg ? . Project ? . DefaultSchemaStatus ?? SchemaStatusEnum . Build ;
118+
119+ // Load build schemas from .env file (same logic as vNext generators)
120+ try
121+ {
122+ var workingDir = Utils . DirectoryUtils . GetWorkingDirectory ( ) ;
123+ var envConfig = EnvConfiguration . Load ( projectRoot : workingDir ) ;
124+ if ( envConfig . BuildSchemas != null && envConfig . BuildSchemas . Count > 0 )
125+ {
126+ buildSchemas = envConfig . BuildSchemas . ToList ( ) ;
127+ _console . Verbose ( $ "[snapshot-provider] using BuildSchemas from .env: { string . Join ( "," , buildSchemas ) } ") ;
128+ }
129+ }
130+ catch
131+ {
132+ // Fallback to direct environment variable check (legacy behavior)
133+ var buildSchemasRaw = Environment . GetEnvironmentVariable ( "SPOCR_BUILD_SCHEMAS" ) ;
134+ if ( ! string . IsNullOrWhiteSpace ( buildSchemasRaw ) )
135+ {
136+ buildSchemas = buildSchemasRaw . Split ( ',' )
137+ . Select ( s => s . Trim ( ) )
138+ . Where ( s => ! string . IsNullOrWhiteSpace ( s ) )
139+ . ToList ( ) ;
140+ _console . Verbose ( $ "[snapshot-provider] using SPOCR_BUILD_SCHEMAS from environment: { string . Join ( "," , buildSchemas ) } ") ;
141+ }
142+ }
116143 }
117144 catch { ignored = new List < string > ( ) ; }
118145
@@ -121,9 +148,18 @@ public IReadOnlyList<SchemaModel> GetSchemas()
121148
122149 var schemas = snapshot . Schemas . Select ( s =>
123150 {
124- // Derive status: if default=Ignore we promote all non-explicit schemas to Build (first-run + subsequent semantics)
151+ // Derive status: check SPOCR_BUILD_SCHEMAS first (positive allow-list), then fall back to legacy ignore logic
125152 SchemaStatusEnum status ;
126- if ( defaultStatus == SchemaStatusEnum . Ignore )
153+
154+ // If SPOCR_BUILD_SCHEMAS is specified, use it as positive allow-list
155+ if ( buildSchemas != null && buildSchemas . Any ( ) )
156+ {
157+ status = buildSchemas . Contains ( s . Name , StringComparer . OrdinalIgnoreCase )
158+ ? SchemaStatusEnum . Build
159+ : SchemaStatusEnum . Ignore ;
160+ }
161+ // Otherwise use legacy logic with IgnoredSchemas
162+ else if ( defaultStatus == SchemaStatusEnum . Ignore )
127163 {
128164 status = ignored . Contains ( s . Name , StringComparer . OrdinalIgnoreCase )
129165 ? SchemaStatusEnum . Ignore
@@ -150,10 +186,10 @@ public IReadOnlyList<SchemaModel> GetSchemas()
150186 {
151187 Name = i . Name ,
152188 SqlTypeName = i . SqlTypeName ,
153- IsNullable = i . IsNullable ?? false ,
154- MaxLength = i . MaxLength ?? 0 ,
155- IsOutput = i . IsOutput ?? false ,
156- IsTableType = ! string . IsNullOrWhiteSpace ( i . TableTypeName ) && ! string . IsNullOrWhiteSpace ( i . TableTypeSchema ) ,
189+ IsNullable = i . IsNullable ?? false ,
190+ MaxLength = i . MaxLength ?? 0 ,
191+ IsOutput = i . IsOutput ?? false ,
192+ IsTableType = ! string . IsNullOrWhiteSpace ( i . TableTypeName ) && ! string . IsNullOrWhiteSpace ( i . TableTypeSchema ) ,
157193 UserTypeName = i . TableTypeName ,
158194 UserTypeSchemaName = i . TableTypeSchema
159195 } ) ) . ToList ( ) ,
0 commit comments