@@ -12,19 +12,26 @@ public static async Task CleanupWriteTableAsync(string connectionString)
1212 await connection . OpenAsync ( ) ;
1313 using var cmd = new SqliteCommand ( "DROP TABLE IF EXISTS order_items" , connection ) ;
1414 await cmd . ExecuteNonQueryAsync ( ) ;
15- await CreateSchemaAsync ( connectionString ) ;
15+ var schemaPath = Path . Combine ( AppContext . BaseDirectory , "schema.sql" ) ;
16+ if ( File . Exists ( schemaPath ) )
17+ {
18+ await CreateSchemaAsync ( connectionString , schemaPath ) ;
19+ }
1620 }
1721
1822 public static async Task InitializeDatabaseAsync ( string connectionString )
1923 {
20- if ( ! File . Exists ( "schema.sql" ) )
21- return ;
22- await CreateSchemaAsync ( connectionString ) ;
24+ var schemaPath = Path . Combine ( AppContext . BaseDirectory , "schema.sql" ) ;
25+ if ( ! File . Exists ( schemaPath ) )
26+ {
27+ throw new FileNotFoundException ( $ "Schema file not found at { schemaPath } . Make sure schema.sql is copied to the output directory.") ;
28+ }
29+ await CreateSchemaAsync ( connectionString , schemaPath ) ;
2330 }
2431
25- private static async Task CreateSchemaAsync ( string connectionString )
32+ private static async Task CreateSchemaAsync ( string connectionString , string schemaPath )
2633 {
27- var schemaSql = await File . ReadAllTextAsync ( "schema.sql" ) ;
34+ var schemaSql = await File . ReadAllTextAsync ( schemaPath ) ;
2835 using var connection = new SqliteConnection ( connectionString ) ;
2936 await connection . OpenAsync ( ) ;
3037 using var command = new SqliteCommand ( schemaSql , connection ) ;
0 commit comments