@@ -55,15 +55,30 @@ class Db extends _$Db with InfraLogger {
5555 }
5656 },
5757 from4To5: (m, schema) async {
58- await m.deleteTable ('geo_asset_entries' );
59- await m.renameColumn (schema.profileEntries, 'test_url' , schema.profileEntries.profileOverride);
60- await m.addColumn (schema.profileEntries, schema.profileEntries.userOverride);
61- await m.addColumn (schema.profileEntries, schema.profileEntries.populatedHeaders);
58+ if (await _tableExists ('geo_asset_entries' )) {
59+ await m.deleteTable ('geo_asset_entries' );
60+ }
6261
63- await m.createTable (schema.appProxyEntries);
62+ final profileTable = schema.profileEntries.actualTableName;
63+ final hasTestUrl = await _columnExists (profileTable, 'test_url' );
64+ final hasProfileOverride = await _columnExists (profileTable, 'profile_override' );
65+ if (hasTestUrl && ! hasProfileOverride) {
66+ await m.renameColumn (schema.profileEntries, 'test_url' , schema.profileEntries.profileOverride);
67+ }
68+ if (! await _columnExists (profileTable, 'user_override' )) {
69+ await m.addColumn (schema.profileEntries, schema.profileEntries.userOverride);
70+ }
71+ if (! await _columnExists (profileTable, 'populated_headers' )) {
72+ await m.addColumn (schema.profileEntries, schema.profileEntries.populatedHeaders);
73+ }
74+ if (! await _tableExists (schema.appProxyEntries.actualTableName)) {
75+ await m.createTable (schema.appProxyEntries);
76+ }
6477 },
6578 from5To6: (m, schema) async {
66- await m.dropColumn (schema.profileEntries, 'profile_override' );
79+ if (await _columnExists (schema.profileEntries.actualTableName, 'profile_override' )) {
80+ await m.dropColumn (schema.profileEntries, 'profile_override' );
81+ }
6782 },
6883 ),
6984 );
@@ -73,6 +88,14 @@ class Db extends _$Db with InfraLogger {
7388 final result = await customSelect ('PRAGMA table_info($table );' ).get ();
7489 return result.any ((row) => row.data['name' ] == column);
7590 }
91+
92+ Future <bool > _tableExists (String table) async {
93+ final result = await customSelect (
94+ 'SELECT 1 FROM sqlite_master WHERE type = ? AND name = ?' ,
95+ variables: [Variable .withString ('table' ), Variable .withString (table)],
96+ ).get ();
97+ return result.isNotEmpty;
98+ }
7699}
77100
78101@DataClassName ('ProfileEntry' )
0 commit comments