mirror of https://github.com/AMT-Cheif/drift.git
Re-generate migration tests in app example
This commit is contained in:
parent
10eb6b9a9c
commit
cf95ed6f05
|
@ -10,4 +10,4 @@ targets:
|
||||||
any_map: true
|
any_map: true
|
||||||
disallow_unrecognized_keys: true
|
disallow_unrecognized_keys: true
|
||||||
field_rename: snake
|
field_rename: snake
|
||||||
create_to_json: false
|
explicit_to_json: true
|
||||||
|
|
|
@ -7,13 +7,7 @@ part 'options.g.dart';
|
||||||
|
|
||||||
/// Controllable options to define the behavior of the analyzer and the
|
/// Controllable options to define the behavior of the analyzer and the
|
||||||
/// generator.
|
/// generator.
|
||||||
@JsonSerializable(
|
@JsonSerializable()
|
||||||
checked: true,
|
|
||||||
anyMap: true,
|
|
||||||
disallowUnrecognizedKeys: true,
|
|
||||||
fieldRename: FieldRename.snake,
|
|
||||||
createToJson: true,
|
|
||||||
)
|
|
||||||
class DriftOptions {
|
class DriftOptions {
|
||||||
static const _defaultSqliteVersion = SqliteVersion.v3(34);
|
static const _defaultSqliteVersion = SqliteVersion.v3(34);
|
||||||
|
|
||||||
|
@ -203,6 +197,8 @@ class DialectOptions {
|
||||||
const DialectOptions(this.dialect, this.options);
|
const DialectOptions(this.dialect, this.options);
|
||||||
|
|
||||||
factory DialectOptions.fromJson(Map json) => _$DialectOptionsFromJson(json);
|
factory DialectOptions.fromJson(Map json) => _$DialectOptionsFromJson(json);
|
||||||
|
|
||||||
|
Map<String, Object?> toJson() => _$DialectOptionsToJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
|
@ -210,7 +206,7 @@ class SqliteAnalysisOptions {
|
||||||
@JsonKey(name: 'modules')
|
@JsonKey(name: 'modules')
|
||||||
final List<SqlModule> modules;
|
final List<SqlModule> modules;
|
||||||
|
|
||||||
@JsonKey(fromJson: _parseSqliteVersion)
|
@_SqliteVersionConverter()
|
||||||
final SqliteVersion? version;
|
final SqliteVersion? version;
|
||||||
|
|
||||||
const SqliteAnalysisOptions({this.modules = const [], this.version});
|
const SqliteAnalysisOptions({this.modules = const [], this.version});
|
||||||
|
@ -218,16 +214,20 @@ class SqliteAnalysisOptions {
|
||||||
factory SqliteAnalysisOptions.fromJson(Map json) {
|
factory SqliteAnalysisOptions.fromJson(Map json) {
|
||||||
return _$SqliteAnalysisOptionsFromJson(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) {
|
const _SqliteVersionConverter();
|
||||||
if (name == null) return null;
|
|
||||||
|
|
||||||
final match = _versionRegex.firstMatch(name);
|
@override
|
||||||
|
SqliteVersion fromJson(String json) {
|
||||||
|
final match = _versionRegex.firstMatch(json);
|
||||||
if (match == null) {
|
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)');
|
'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);
|
final version = SqliteVersion(major, minor, 0);
|
||||||
if (version < SqliteVersion.minimum) {
|
if (version < SqliteVersion.minimum) {
|
||||||
throw ArgumentError.value(
|
throw ArgumentError.value(
|
||||||
name,
|
json,
|
||||||
'name',
|
'json',
|
||||||
'Version is not supported for analysis (minimum is '
|
'Version is not supported for analysis (minimum is '
|
||||||
'${SqliteVersion.minimum}).',
|
'${SqliteVersion.minimum}).',
|
||||||
);
|
);
|
||||||
} else if (version > SqliteVersion.current) {
|
} else if (version > SqliteVersion.current) {
|
||||||
throw ArgumentError.value(
|
throw ArgumentError.value(
|
||||||
name,
|
json,
|
||||||
'name',
|
'json',
|
||||||
'Version is not supported for analysis (current maximum is '
|
'Version is not supported for analysis (current maximum is '
|
||||||
'${SqliteVersion.current}).',
|
'${SqliteVersion.current}).',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return version;
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toJson(SqliteVersion object) {
|
||||||
|
return '${object.major}.${object.minor}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set of sqlite modules that require special knowledge from the generator.
|
/// Set of sqlite modules that require special knowledge from the generator.
|
||||||
|
|
|
@ -130,8 +130,8 @@ Map<String, dynamic> _$DriftOptionsToJson(DriftOptions instance) =>
|
||||||
'generate_connect_constructor': instance.generateConnectConstructor,
|
'generate_connect_constructor': instance.generateConnectConstructor,
|
||||||
'sqlite_modules':
|
'sqlite_modules':
|
||||||
instance.modules.map((e) => _$SqlModuleEnumMap[e]!).toList(),
|
instance.modules.map((e) => _$SqlModuleEnumMap[e]!).toList(),
|
||||||
'sqlite': instance.sqliteAnalysisOptions,
|
'sqlite': instance.sqliteAnalysisOptions?.toJson(),
|
||||||
'sql': instance.dialect,
|
'sql': instance.dialect?.toJson(),
|
||||||
'eagerly_load_dart_ast': instance.eagerlyLoadDartAst,
|
'eagerly_load_dart_ast': instance.eagerlyLoadDartAst,
|
||||||
'data_class_to_companions': instance.dataClassToCompanions,
|
'data_class_to_companions': instance.dataClassToCompanions,
|
||||||
'mutable_classes': instance.generateMutableClasses,
|
'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 = {
|
const _$SqlDialectEnumMap = {
|
||||||
SqlDialect.sqlite: 'sqlite',
|
SqlDialect.sqlite: 'sqlite',
|
||||||
SqlDialect.mysql: 'mysql',
|
SqlDialect.mysql: 'mysql',
|
||||||
|
@ -196,8 +202,30 @@ SqliteAnalysisOptions _$SqliteAnalysisOptionsFromJson(Map json) =>
|
||||||
.toList() ??
|
.toList() ??
|
||||||
const []),
|
const []),
|
||||||
version: $checkedConvert(
|
version: $checkedConvert(
|
||||||
'version', (v) => _parseSqliteVersion(v as String?)),
|
'version',
|
||||||
|
(v) => _$JsonConverterFromJson<String, SqliteVersion>(
|
||||||
|
v, const _SqliteVersionConverter().fromJson)),
|
||||||
);
|
);
|
||||||
return val;
|
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);
|
||||||
|
|
|
@ -7,17 +7,17 @@ class Categories extends Table with TableInfo {
|
||||||
final GeneratedDatabase attachedDatabase;
|
final GeneratedDatabase attachedDatabase;
|
||||||
final String? _alias;
|
final String? _alias;
|
||||||
Categories(this.attachedDatabase, [this._alias]);
|
Categories(this.attachedDatabase, [this._alias]);
|
||||||
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||||
'id', aliasedName, false,
|
'id', aliasedName, false,
|
||||||
type: const IntType(),
|
type: DriftSqlType.int,
|
||||||
requiredDuringInsert: false,
|
requiredDuringInsert: false,
|
||||||
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
||||||
late final GeneratedColumn<String?> name = GeneratedColumn<String?>(
|
late final GeneratedColumn<String> name = GeneratedColumn<String>(
|
||||||
'name', aliasedName, false,
|
'name', aliasedName, false,
|
||||||
type: const StringType(), requiredDuringInsert: true);
|
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||||
late final GeneratedColumn<int?> color = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> color = GeneratedColumn<int>(
|
||||||
'color', aliasedName, false,
|
'color', aliasedName, false,
|
||||||
type: const IntType(), requiredDuringInsert: true);
|
type: DriftSqlType.int, requiredDuringInsert: true);
|
||||||
@override
|
@override
|
||||||
List<GeneratedColumn> get $columns => [id, name, color];
|
List<GeneratedColumn> get $columns => [id, name, color];
|
||||||
@override
|
@override
|
||||||
|
@ -45,17 +45,17 @@ class TodoEntries extends Table with TableInfo {
|
||||||
final GeneratedDatabase attachedDatabase;
|
final GeneratedDatabase attachedDatabase;
|
||||||
final String? _alias;
|
final String? _alias;
|
||||||
TodoEntries(this.attachedDatabase, [this._alias]);
|
TodoEntries(this.attachedDatabase, [this._alias]);
|
||||||
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||||
'id', aliasedName, false,
|
'id', aliasedName, false,
|
||||||
type: const IntType(),
|
type: DriftSqlType.int,
|
||||||
requiredDuringInsert: false,
|
requiredDuringInsert: false,
|
||||||
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
||||||
late final GeneratedColumn<String?> description = GeneratedColumn<String?>(
|
late final GeneratedColumn<String> description = GeneratedColumn<String>(
|
||||||
'description', aliasedName, false,
|
'description', aliasedName, false,
|
||||||
type: const StringType(), requiredDuringInsert: true);
|
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||||
late final GeneratedColumn<int?> category = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> category = GeneratedColumn<int>(
|
||||||
'category', aliasedName, true,
|
'category', aliasedName, true,
|
||||||
type: const IntType(), requiredDuringInsert: false);
|
type: DriftSqlType.int, requiredDuringInsert: false);
|
||||||
@override
|
@override
|
||||||
List<GeneratedColumn> get $columns => [id, description, category];
|
List<GeneratedColumn> get $columns => [id, description, category];
|
||||||
@override
|
@override
|
||||||
|
@ -109,7 +109,7 @@ class text_entriesTable extends Table with TableInfo, VirtualTableInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DatabaseAtV1 extends GeneratedDatabase {
|
class DatabaseAtV1 extends GeneratedDatabase {
|
||||||
DatabaseAtV1(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
|
DatabaseAtV1(QueryExecutor e) : super(e);
|
||||||
DatabaseAtV1.connect(DatabaseConnection c) : super.connect(c);
|
DatabaseAtV1.connect(DatabaseConnection c) : super.connect(c);
|
||||||
late final Categories categories = Categories(this);
|
late final Categories categories = Categories(this);
|
||||||
late final TodoEntries todoEntries = TodoEntries(this);
|
late final TodoEntries todoEntries = TodoEntries(this);
|
||||||
|
|
|
@ -7,17 +7,17 @@ class Categories extends Table with TableInfo {
|
||||||
final GeneratedDatabase attachedDatabase;
|
final GeneratedDatabase attachedDatabase;
|
||||||
final String? _alias;
|
final String? _alias;
|
||||||
Categories(this.attachedDatabase, [this._alias]);
|
Categories(this.attachedDatabase, [this._alias]);
|
||||||
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||||
'id', aliasedName, false,
|
'id', aliasedName, false,
|
||||||
type: const IntType(),
|
type: DriftSqlType.int,
|
||||||
requiredDuringInsert: false,
|
requiredDuringInsert: false,
|
||||||
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
||||||
late final GeneratedColumn<String?> name = GeneratedColumn<String?>(
|
late final GeneratedColumn<String> name = GeneratedColumn<String>(
|
||||||
'name', aliasedName, false,
|
'name', aliasedName, false,
|
||||||
type: const StringType(), requiredDuringInsert: true);
|
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||||
late final GeneratedColumn<int?> color = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> color = GeneratedColumn<int>(
|
||||||
'color', aliasedName, false,
|
'color', aliasedName, false,
|
||||||
type: const IntType(), requiredDuringInsert: true);
|
type: DriftSqlType.int, requiredDuringInsert: true);
|
||||||
@override
|
@override
|
||||||
List<GeneratedColumn> get $columns => [id, name, color];
|
List<GeneratedColumn> get $columns => [id, name, color];
|
||||||
@override
|
@override
|
||||||
|
@ -45,20 +45,20 @@ class TodoEntries extends Table with TableInfo {
|
||||||
final GeneratedDatabase attachedDatabase;
|
final GeneratedDatabase attachedDatabase;
|
||||||
final String? _alias;
|
final String? _alias;
|
||||||
TodoEntries(this.attachedDatabase, [this._alias]);
|
TodoEntries(this.attachedDatabase, [this._alias]);
|
||||||
late final GeneratedColumn<int?> id = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> id = GeneratedColumn<int>(
|
||||||
'id', aliasedName, false,
|
'id', aliasedName, false,
|
||||||
type: const IntType(),
|
type: DriftSqlType.int,
|
||||||
requiredDuringInsert: false,
|
requiredDuringInsert: false,
|
||||||
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
|
||||||
late final GeneratedColumn<String?> description = GeneratedColumn<String?>(
|
late final GeneratedColumn<String> description = GeneratedColumn<String>(
|
||||||
'description', aliasedName, false,
|
'description', aliasedName, false,
|
||||||
type: const StringType(), requiredDuringInsert: true);
|
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||||
late final GeneratedColumn<int?> category = GeneratedColumn<int?>(
|
late final GeneratedColumn<int> category = GeneratedColumn<int>(
|
||||||
'category', aliasedName, true,
|
'category', aliasedName, true,
|
||||||
type: const IntType(), requiredDuringInsert: false);
|
type: DriftSqlType.int, requiredDuringInsert: false);
|
||||||
late final GeneratedColumn<DateTime?> dueDate = GeneratedColumn<DateTime?>(
|
late final GeneratedColumn<DateTime> dueDate = GeneratedColumn<DateTime>(
|
||||||
'due_date', aliasedName, true,
|
'due_date', aliasedName, true,
|
||||||
type: const IntType(), requiredDuringInsert: false);
|
type: DriftSqlType.dateTime, requiredDuringInsert: false);
|
||||||
@override
|
@override
|
||||||
List<GeneratedColumn> get $columns => [id, description, category, dueDate];
|
List<GeneratedColumn> get $columns => [id, description, category, dueDate];
|
||||||
@override
|
@override
|
||||||
|
@ -112,7 +112,7 @@ class text_entriesTable extends Table with TableInfo, VirtualTableInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
class DatabaseAtV2 extends GeneratedDatabase {
|
class DatabaseAtV2 extends GeneratedDatabase {
|
||||||
DatabaseAtV2(QueryExecutor e) : super(SqlTypeSystem.defaultInstance, e);
|
DatabaseAtV2(QueryExecutor e) : super(e);
|
||||||
DatabaseAtV2.connect(DatabaseConnection c) : super.connect(c);
|
DatabaseAtV2.connect(DatabaseConnection c) : super.connect(c);
|
||||||
late final Categories categories = Categories(this);
|
late final Categories categories = Categories(this);
|
||||||
late final TodoEntries todoEntries = TodoEntries(this);
|
late final TodoEntries todoEntries = TodoEntries(this);
|
||||||
|
|
Loading…
Reference in New Issue