Re-generate migration tests in app example

This commit is contained in:
Simon Binder 2022-07-29 18:54:41 +02:00
parent 10eb6b9a9c
commit cf95ed6f05
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 101 additions and 67 deletions

View File

@ -10,4 +10,4 @@ targets:
any_map: true
disallow_unrecognized_keys: true
field_rename: snake
create_to_json: false
explicit_to_json: true

View File

@ -7,13 +7,7 @@ part 'options.g.dart';
/// Controllable options to define the behavior of the analyzer and the
/// generator.
@JsonSerializable(
checked: true,
anyMap: true,
disallowUnrecognizedKeys: true,
fieldRename: FieldRename.snake,
createToJson: true,
)
@JsonSerializable()
class DriftOptions {
static const _defaultSqliteVersion = SqliteVersion.v3(34);
@ -203,6 +197,8 @@ class DialectOptions {
const DialectOptions(this.dialect, this.options);
factory DialectOptions.fromJson(Map json) => _$DialectOptionsFromJson(json);
Map<String, Object?> toJson() => _$DialectOptionsToJson(this);
}
@JsonSerializable()
@ -210,7 +206,7 @@ class SqliteAnalysisOptions {
@JsonKey(name: 'modules')
final List<SqlModule> modules;
@JsonKey(fromJson: _parseSqliteVersion)
@_SqliteVersionConverter()
final SqliteVersion? version;
const SqliteAnalysisOptions({this.modules = const [], this.version});
@ -218,16 +214,20 @@ class SqliteAnalysisOptions {
factory SqliteAnalysisOptions.fromJson(Map json) {
return _$SqliteAnalysisOptionsFromJson(json);
}
Map<String, Object?> toJson() => _$SqliteAnalysisOptionsToJson(this);
}
final _versionRegex = RegExp(r'(\d+)\.(\d+)');
class _SqliteVersionConverter extends JsonConverter<SqliteVersion, String> {
static final _versionRegex = RegExp(r'(\d+)\.(\d+)');
SqliteVersion? _parseSqliteVersion(String? name) {
if (name == null) return null;
const _SqliteVersionConverter();
final match = _versionRegex.firstMatch(name);
@override
SqliteVersion fromJson(String json) {
final match = _versionRegex.firstMatch(json);
if (match == null) {
throw ArgumentError.value(name, 'name',
throw ArgumentError.value(json, 'json',
'Not a valid sqlite version: Expected format major.minor (e.g. 3.34)');
}
@ -237,21 +237,27 @@ SqliteVersion? _parseSqliteVersion(String? name) {
final version = SqliteVersion(major, minor, 0);
if (version < SqliteVersion.minimum) {
throw ArgumentError.value(
name,
'name',
json,
'json',
'Version is not supported for analysis (minimum is '
'${SqliteVersion.minimum}).',
);
} else if (version > SqliteVersion.current) {
throw ArgumentError.value(
name,
'name',
json,
'json',
'Version is not supported for analysis (current maximum is '
'${SqliteVersion.current}).',
);
}
return version;
}
@override
String toJson(SqliteVersion object) {
return '${object.major}.${object.minor}';
}
}
/// Set of sqlite modules that require special knowledge from the generator.

View File

@ -130,8 +130,8 @@ Map<String, dynamic> _$DriftOptionsToJson(DriftOptions instance) =>
'generate_connect_constructor': instance.generateConnectConstructor,
'sqlite_modules':
instance.modules.map((e) => _$SqlModuleEnumMap[e]!).toList(),
'sqlite': instance.sqliteAnalysisOptions,
'sql': instance.dialect,
'sqlite': instance.sqliteAnalysisOptions?.toJson(),
'sql': instance.dialect?.toJson(),
'eagerly_load_dart_ast': instance.eagerlyLoadDartAst,
'data_class_to_companions': instance.dataClassToCompanions,
'mutable_classes': instance.generateMutableClasses,
@ -172,6 +172,12 @@ DialectOptions _$DialectOptionsFromJson(Map json) => $checkedCreate(
},
);
Map<String, dynamic> _$DialectOptionsToJson(DialectOptions instance) =>
<String, dynamic>{
'dialect': _$SqlDialectEnumMap[instance.dialect]!,
'options': instance.options?.toJson(),
};
const _$SqlDialectEnumMap = {
SqlDialect.sqlite: 'sqlite',
SqlDialect.mysql: 'mysql',
@ -196,8 +202,30 @@ SqliteAnalysisOptions _$SqliteAnalysisOptionsFromJson(Map json) =>
.toList() ??
const []),
version: $checkedConvert(
'version', (v) => _parseSqliteVersion(v as String?)),
'version',
(v) => _$JsonConverterFromJson<String, SqliteVersion>(
v, const _SqliteVersionConverter().fromJson)),
);
return val;
},
);
Map<String, dynamic> _$SqliteAnalysisOptionsToJson(
SqliteAnalysisOptions instance) =>
<String, dynamic>{
'modules': instance.modules.map((e) => _$SqlModuleEnumMap[e]!).toList(),
'version': _$JsonConverterToJson<String, SqliteVersion>(
instance.version, const _SqliteVersionConverter().toJson),
};
Value? _$JsonConverterFromJson<Json, Value>(
Object? json,
Value? Function(Json json) fromJson,
) =>
json == null ? null : fromJson(json as Json);
Json? _$JsonConverterToJson<Json, Value>(
Value? value,
Json? Function(Value value) toJson,
) =>
value == null ? null : toJson(value);

View File

@ -7,17 +7,17 @@ class Categories extends Table with TableInfo {
final GeneratedDatabase attachedDatabase;
final String? _alias;
Categories(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: const IntType(),
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String?> name = GeneratedColumn<String?>(
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: const StringType(), requiredDuringInsert: true);
late final GeneratedColumn<int?> color = GeneratedColumn<int?>(
type: DriftSqlType.string, requiredDuringInsert: true);
late final GeneratedColumn<int> color = GeneratedColumn<int>(
'color', aliasedName, false,
type: const IntType(), requiredDuringInsert: true);
type: DriftSqlType.int, requiredDuringInsert: true);
@override
List<GeneratedColumn> get $columns => [id, name, color];
@override
@ -45,17 +45,17 @@ class TodoEntries extends Table with TableInfo {
final GeneratedDatabase attachedDatabase;
final String? _alias;
TodoEntries(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: const IntType(),
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String?> description = GeneratedColumn<String?>(
late final GeneratedColumn<String> description = GeneratedColumn<String>(
'description', aliasedName, false,
type: const StringType(), requiredDuringInsert: true);
late final GeneratedColumn<int?> category = GeneratedColumn<int?>(
type: DriftSqlType.string, requiredDuringInsert: true);
late final GeneratedColumn<int> category = GeneratedColumn<int>(
'category', aliasedName, true,
type: const IntType(), requiredDuringInsert: false);
type: DriftSqlType.int, requiredDuringInsert: false);
@override
List<GeneratedColumn> get $columns => [id, description, category];
@override
@ -109,7 +109,7 @@ class text_entriesTable extends Table with TableInfo, VirtualTableInfo {
}
class DatabaseAtV1 extends GeneratedDatabase {
DatabaseAtV1(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
DatabaseAtV1(QueryExecutor e) : super(e);
DatabaseAtV1.connect(DatabaseConnection c) : super.connect(c);
late final Categories categories = Categories(this);
late final TodoEntries todoEntries = TodoEntries(this);

View File

@ -7,17 +7,17 @@ class Categories extends Table with TableInfo {
final GeneratedDatabase attachedDatabase;
final String? _alias;
Categories(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: const IntType(),
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String?> name = GeneratedColumn<String?>(
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: const StringType(), requiredDuringInsert: true);
late final GeneratedColumn<int?> color = GeneratedColumn<int?>(
type: DriftSqlType.string, requiredDuringInsert: true);
late final GeneratedColumn<int> color = GeneratedColumn<int>(
'color', aliasedName, false,
type: const IntType(), requiredDuringInsert: true);
type: DriftSqlType.int, requiredDuringInsert: true);
@override
List<GeneratedColumn> get $columns => [id, name, color];
@override
@ -45,20 +45,20 @@ class TodoEntries extends Table with TableInfo {
final GeneratedDatabase attachedDatabase;
final String? _alias;
TodoEntries(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: const IntType(),
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String?> description = GeneratedColumn<String?>(
late final GeneratedColumn<String> description = GeneratedColumn<String>(
'description', aliasedName, false,
type: const StringType(), requiredDuringInsert: true);
late final GeneratedColumn<int?> category = GeneratedColumn<int?>(
type: DriftSqlType.string, requiredDuringInsert: true);
late final GeneratedColumn<int> category = GeneratedColumn<int>(
'category', aliasedName, true,
type: const IntType(), requiredDuringInsert: false);
late final GeneratedColumn<DateTime?> dueDate = GeneratedColumn<DateTime?>(
type: DriftSqlType.int, requiredDuringInsert: false);
late final GeneratedColumn<DateTime> dueDate = GeneratedColumn<DateTime>(
'due_date', aliasedName, true,
type: const IntType(), requiredDuringInsert: false);
type: DriftSqlType.dateTime, requiredDuringInsert: false);
@override
List<GeneratedColumn> get $columns => [id, description, category, dueDate];
@override
@ -112,7 +112,7 @@ class text_entriesTable extends Table with TableInfo, VirtualTableInfo {
}
class DatabaseAtV2 extends GeneratedDatabase {
DatabaseAtV2(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
DatabaseAtV2(QueryExecutor e) : super(e);
DatabaseAtV2.connect(DatabaseConnection c) : super.connect(c);
late final Categories categories = Categories(this);
late final TodoEntries todoEntries = TodoEntries(this);