Schema does not match #2028
-
Hi, im trying to test migrations but Im getting this error:
this is my migration code: class UpgradeFrom13To14 extends MigrationUpgrade {
const UpgradeFrom13To14(final Database database) : super(database);
@override
Future<void> onUpgrade(final Migrator m, final int from, final int to) async {
await database.customStatement(
'ALTER TABLE ${database.games.actualTableName} '
'ADD COLUMN ${database.games.textColor.name} INTEGER NOT NULL DEFAULT 1;',
);
}
} schema: {"_meta":{"description":"This file contains a serialized version of schema entities for moor.","version":"0.1.0-dev-preview"},"entities":[{"id":0,"references":[],"type":"table","data":{"name":"users","was_declared_in_moor":false,"columns":[{"name":"id","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":["auto-increment","primary-key"]},{"name":"user_id","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"username","moor_type":"ColumnType.text","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"fcm_token","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"sso_uid","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"email","moor_type":"ColumnType.text","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":false}},{"id":1,"references":[],"type":"table","data":{"name":"games","was_declared_in_moor":false,"columns":[{"name":"id","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":["auto-increment","primary-key"]},{"name":"game_id","moor_type":"ColumnType.text","nullable":false,"customConstraints":"UNIQUE","default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"name","moor_type":"ColumnType.text","nullable":false,"customConstraints":"UNIQUE","default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"short_name","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"description","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"image_url","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"primary_color","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"accent_color","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"secondary_color","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"text_color","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":false}},{"id":2,"references":[],"type":"table","data":{"name":"user_games_entries","was_declared_in_moor":false,"columns":[{"name":"user_id","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"game_id","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":false}}]} test('migration from v13 to v14', () async {
final schema = await verifier.schemaAt(13);
final oldDb = v13.DatabaseAtV13(schema.newConnection().executor);
await oldDb.into(oldDb.games).insert(
const v13.GamesCompanion(
id: Value(1),
gameId: Value('id'),
name: Value('userId'),
shortName: Value('fcmToken'),
description: Value('ssoUid'),
imageUrl: Value('email'),
primaryColor: Value(1),
secondaryColor: Value(1),
accentColor: Value(1),
),
);
await oldDb.close();
// Run migration from 12 to 13
final db = Database(schema.newConnection().executor);
await verifier.migrateAndValidate(db, 14); // FAILING HERE
await db.close(); *drift 2.1.0 but was also happening on 1.7.0 Anyone knows whats wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Looking at the schema json, it seems like the A column with a definition of |
Beta Was this translation helpful? Give feedback.
-
@simolus3 @DataClassName('GameEntry') TextColumn get gameId => text().customConstraint('UNIQUE')(); TextColumn get name => text().customConstraint('UNIQUE')(); TextColumn get shortName => text()(); TextColumn get description => text()(); TextColumn get imageUrl => text()(); IntColumn get primaryColor => integer()(); IntColumn get accentColor => integer()(); IntColumn get secondaryColor => integer()(); IntColumn get textColor => integer().withDefault(const Constant(1))(); |
Beta Was this translation helpful? Give feedback.
-
my bad, was runnning commands in different order |
Beta Was this translation helpful? Give feedback.
Looking at the schema json, it seems like the
DEFAULT 1
is indeed unexpected.A column with a definition of
NOT NULL DEFAULT 1
is different from aNOT NULL
-only column, so drift complains about the found difference. Everything seems to be working as intended here? If you want the default to be there, you also need to define the column with that default in the original table used by the main database.