Schema tool: Store whether dates are text

This commit is contained in:
Simon Binder 2022-07-26 19:18:17 +02:00
parent 9158c31240
commit 0cb3527680
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
21 changed files with 943 additions and 39 deletions

View File

@ -12,7 +12,7 @@ part 'options.g.dart';
anyMap: true,
disallowUnrecognizedKeys: true,
fieldRename: FieldRename.snake,
createToJson: false,
createToJson: true,
)
class DriftOptions {
static const _defaultSqliteVersion = SqliteVersion.v3(34);
@ -191,6 +191,8 @@ class DriftOptions {
SqliteVersion get sqliteVersion {
return sqliteOptions?.version ?? _defaultSqliteVersion;
}
Map<String, Object?> toJson() => _$DriftOptionsToJson(this);
}
@JsonSerializable()

View File

@ -115,6 +115,36 @@ DriftOptions _$DriftOptionsFromJson(Map json) => $checkedCreate(
},
);
Map<String, dynamic> _$DriftOptionsToJson(DriftOptions instance) =>
<String, dynamic>{
'write_from_json_string_constructor':
instance.generateFromJsonStringConstructor,
'override_hash_and_equals_in_result_sets':
instance.overrideHashAndEqualsInResultSets,
'compact_query_methods': instance.compactQueryMethods,
'skip_verification_code': instance.skipVerificationCode,
'use_data_class_name_for_companions':
instance.useDataClassNameForCompanions,
'use_column_name_as_json_key_when_defined_in_moor_file':
instance.useColumnNameAsJsonKeyWhenDefinedInMoorFile,
'generate_connect_constructor': instance.generateConnectConstructor,
'sqlite_modules':
instance.modules.map((e) => _$SqlModuleEnumMap[e]!).toList(),
'sqlite': instance.sqliteAnalysisOptions,
'sql': instance.dialect,
'eagerly_load_dart_ast': instance.eagerlyLoadDartAst,
'data_class_to_companions': instance.dataClassToCompanions,
'mutable_classes': instance.generateMutableClasses,
'raw_result_set_data': instance.rawResultSetData,
'apply_converters_on_variables': instance.applyConvertersOnVariables,
'generate_values_in_copy_with': instance.generateValuesInCopyWith,
'named_parameters': instance.generateNamedParameters,
'named_parameters_always_required':
instance.namedParametersAlwaysRequired,
'scoped_dart_components': instance.scopedDartComponents,
'store_date_time_values_as_text': instance.storeDateTimeValuesAsText,
};
const _$SqlModuleEnumMap = {
SqlModule.json1: 'json1',
SqlModule.fts5: 'fts5',

View File

@ -50,7 +50,7 @@ class DumpSchemaCommand extends Command {
}
final db = result.declaredDatabases.single;
final writer = SchemaWriter(db);
final writer = SchemaWriter(db, options: cli.project.moorOptions);
var target = rest[1];
// This command is most commonly used to write into

View File

@ -9,6 +9,8 @@ import 'package:drift_dev/src/services/schema/schema_files.dart';
import 'package:drift_dev/writer.dart';
import 'package:path/path.dart' as p;
import '../../../analyzer/options.dart';
class GenerateUtilsCommand extends Command {
final MoorCli cli;
@ -78,9 +80,8 @@ class GenerateUtilsCommand extends Command {
'Wrote ${schema.length + 1} files into ${p.relative(outputDir.path)}');
}
Future<Map<int, List<DriftSchemaEntity>>> _parseSchema(
Directory directory) async {
final results = <int, List<DriftSchemaEntity>>{};
Future<Map<int, _ExportedSchema>> _parseSchema(Directory directory) async {
final results = <int, _ExportedSchema>{};
await for (final entity in directory.list()) {
final basename = p.basename(entity.path);
@ -92,7 +93,8 @@ class GenerateUtilsCommand extends Command {
final rawData = json.decode(await entity.readAsString());
final schema = SchemaReader.readJson(rawData as Map<String, dynamic>);
results[version] = schema.entities.toList();
results[version] =
_ExportedSchema(schema.entities.toList(), schema.options);
}
return results;
@ -101,13 +103,20 @@ class GenerateUtilsCommand extends Command {
Future<void> _writeSchemaFile(
Directory output,
int version,
List<DriftSchemaEntity> entities,
_ExportedSchema schema,
bool dataClasses,
bool companions,
bool isForMoor,
) {
// let serialized options take precedence, otherwise use current options
// from project.
final options = DriftOptions.fromJson({
...cli.project.moorOptions.toJson(),
...schema.options,
});
final writer = Writer(
cli.project.moorOptions,
options,
generationOptions: GenerationOptions(
forSchema: version,
writeCompanions: companions,
@ -131,7 +140,7 @@ class GenerateUtilsCommand extends Command {
declaredQueries: const [],
declaredIncludes: const [],
declaredTables: const [],
)..entities = entities;
)..entities = schema.schema;
DatabaseWriter(db, writer.child()).write();
return file.writeAsString(_dartfmt.format(writer.writeGenerated()));
@ -186,3 +195,10 @@ class GenerateUtilsCommand extends Command {
static final _dartfmt = DartFormatter();
static const _prefix = '// GENERATED CODE, DO NOT EDIT BY HAND.';
}
class _ExportedSchema {
final List<DriftSchemaEntity> schema;
final Map<String, Object?> options;
_ExportedSchema(this.schema, this.options);
}

View File

@ -5,19 +5,19 @@ import 'package:sqlparser/sqlparser.dart';
import '../../writer/utils/column_constraints.dart';
const _infoVersion = '0.1.0-dev-preview';
const _infoVersion = '1.0.0';
/// Utilities to transform moor schema entities to json.
class SchemaWriter {
static const _exportOptions = DriftOptions.defaults();
/// The parsed and resolved database for which the schema should be written.
final Database db;
final DriftOptions options;
final Map<DriftSchemaEntity, int> _entityIds = {};
int _maxId = 0;
SchemaWriter(this.db);
SchemaWriter(this.db, {this.options = const DriftOptions.defaults()});
int _idOf(DriftSchemaEntity entity) {
return _entityIds.putIfAbsent(entity, () => _maxId++);
@ -27,15 +27,24 @@ class SchemaWriter {
return {
'_meta': {
'description': 'This file contains a serialized version of schema '
'entities for moor.',
'entities for drift.',
'version': _infoVersion,
},
'options': _serializeOptions(),
'entities': [
for (final entity in db.entities) _entityToJson(entity),
],
};
}
Map _serializeOptions() {
const relevantKeys = {'store_date_time_values_as_text'};
final asJson = options.toJson()
..removeWhere((key, _) => !relevantKeys.contains(key));
return asJson;
}
Map _entityToJson(DriftSchemaEntity entity) {
String type;
Map data;
@ -51,7 +60,7 @@ class SchemaWriter {
for (final ref in entity.bodyReferences) _idOf(ref),
],
'name': entity.displayName,
'sql': entity.createSql(_exportOptions),
'sql': entity.createSql(options),
};
} else if (entity is MoorIndex) {
type = 'index';
@ -160,6 +169,7 @@ class SchemaReader {
final Set<int> _currentlyProcessing = {};
final SqlEngine _engine = SqlEngine();
Map<String, Object?> options = const {};
SchemaReader._();
@ -170,6 +180,13 @@ class SchemaReader {
Iterable<DriftSchemaEntity> get entities => _entitiesById.values;
void _read(Map<String, dynamic> json) {
// Read drift options if they are part of the schema file.
final optionsInJson = json['options'] as Map<String, Object?>?;
options = optionsInJson ??
{
'store_date_time_values_as_text': false,
};
final entities = json['entities'] as List<dynamic>;
for (final raw in entities) {

View File

@ -74,11 +74,19 @@ class Database {}
final schemaJson = SchemaWriter(db).createSchemaJson();
expect(schemaJson, json.decode(expected));
final schemaWithOptions = SchemaWriter(
db,
options: const DriftOptions.defaults(storeDateTimeValuesAsText: true),
).createSchemaJson();
expect(
schemaWithOptions['options'], {'store_date_time_values_as_text': true});
});
test('can generate code from schema json', () {
final reader =
SchemaReader.readJson(json.decode(expected) as Map<String, dynamic>);
final serializedSchema = json.decode(expected) as Map<String, dynamic>;
final reader = SchemaReader.readJson(serializedSchema);
final fakeDb = Database()..entities = [...reader.entities];
// Write the database. Not crashing is good enough for us here, we have
@ -92,8 +100,11 @@ class Database {}
const expected = r'''
{
"_meta": {
"description": "This file contains a serialized version of schema entities for moor.",
"version": "0.1.0-dev-preview"
"description": "This file contains a serialized version of schema entities for drift.",
"version": "1.0.0"
},
"options": {
"store_date_time_values_as_text": false
},
"entities": [
{

View File

@ -4,3 +4,4 @@ targets:
drift_dev:
options:
generate_connect_constructor: true
store_date_time_values_as_text: true

View File

@ -0,0 +1 @@
{"_meta":{"description":"This file contains a serialized version of schema entities for drift.","version":"1.0.0"},"options":{"store_date_time_values_as_text":true},"entities":[{"id":0,"references":[],"type":"table","data":{"name":"users","was_declared_in_moor":false,"columns":[{"name":"id","getter_name":"id","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"defaultConstraints":"PRIMARY KEY AUTOINCREMENT","default_dart":null,"default_client_dart":null,"dsl_features":["auto-increment","primary-key"]},{"name":"name","getter_name":"name","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":"const Constant('name')","default_client_dart":null,"dsl_features":[]},{"name":"birthday","getter_name":"birthday","moor_type":"ColumnType.datetime","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"next_user","getter_name":"nextUser","moor_type":"ColumnType.integer","nullable":true,"customConstraints":null,"defaultConstraints":"REFERENCES users (id)","default_dart":null,"default_client_dart":null,"dsl_features":["unknown"]}],"is_virtual":false}},{"id":1,"references":[0],"type":"table","data":{"name":"groups","was_declared_in_moor":true,"columns":[{"name":"id","getter_name":"id","moor_type":"ColumnType.integer","nullable":false,"customConstraints":"NOT NULL","default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"title","getter_name":"title","moor_type":"ColumnType.text","nullable":false,"customConstraints":"NOT NULL","default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"deleted","getter_name":"deleted","moor_type":"ColumnType.boolean","nullable":true,"customConstraints":"DEFAULT FALSE","default_dart":"const CustomExpression<bool>('FALSE')","default_client_dart":null,"dsl_features":[]},{"name":"owner","getter_name":"owner","moor_type":"ColumnType.integer","nullable":false,"customConstraints":"NOT NULL REFERENCES users (id)","default_dart":null,"default_client_dart":null,"dsl_features":[]}],"is_virtual":false,"constraints":["PRIMARY KEY (id)"],"explicit_pk":["id"]}},{"id":2,"references":[1,0],"type":"view","data":{"name":"group_count","sql":"CREATE VIEW group_count AS SELECT users.*, (SELECT COUNT(*) FROM \"groups\" WHERE owner = users.id) AS group_count FROM users","dart_data_name":"GroupCountData","dart_info_name":"GroupCount","columns":[{"name":"id","getter_name":"id","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"name","getter_name":"name","moor_type":"ColumnType.text","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"birthday","getter_name":"birthday","moor_type":"ColumnType.datetime","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"next_user","getter_name":"nextUser","moor_type":"ColumnType.integer","nullable":true,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]},{"name":"group_count","getter_name":"groupCount","moor_type":"ColumnType.integer","nullable":false,"customConstraints":null,"default_dart":null,"default_client_dart":null,"dsl_features":[]}]}}]}

View File

@ -9,7 +9,7 @@ part 'database.g.dart';
@DriftDatabase(include: {'tables.drift'})
class Database extends _$Database {
@override
int get schemaVersion => 5;
int get schemaVersion => 6;
Database(DatabaseConnection connection) : super.connect(connection);
@ -47,6 +47,8 @@ class Database extends _$Database {
// And create the view on users
await m.createView(groupCount);
} else if (target == 6) {
await m.addColumn(users, users.birthday);
}
}
},

View File

@ -10,13 +10,18 @@ part of 'database.dart';
class User extends DataClass implements Insertable<User> {
final int id;
final String name;
final DateTime? birthday;
final int? nextUser;
const User({required this.id, required this.name, this.nextUser});
const User(
{required this.id, required this.name, this.birthday, this.nextUser});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<int>(id);
map['name'] = Variable<String>(name);
if (!nullToAbsent || birthday != null) {
map['birthday'] = Variable<DateTime>(birthday);
}
if (!nullToAbsent || nextUser != null) {
map['next_user'] = Variable<int>(nextUser);
}
@ -27,6 +32,9 @@ class User extends DataClass implements Insertable<User> {
return UsersCompanion(
id: Value(id),
name: Value(name),
birthday: birthday == null && nullToAbsent
? const Value.absent()
: Value(birthday),
nextUser: nextUser == null && nullToAbsent
? const Value.absent()
: Value(nextUser),
@ -39,6 +47,7 @@ class User extends DataClass implements Insertable<User> {
return User(
id: serializer.fromJson<int>(json['id']),
name: serializer.fromJson<String>(json['name']),
birthday: serializer.fromJson<DateTime?>(json['birthday']),
nextUser: serializer.fromJson<int?>(json['nextUser']),
);
}
@ -48,13 +57,16 @@ class User extends DataClass implements Insertable<User> {
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'name': serializer.toJson<String>(name),
'birthday': serializer.toJson<DateTime?>(birthday),
'nextUser': serializer.toJson<int?>(nextUser),
};
}
User copyWith({int? id, String? name, int? nextUser}) => User(
User copyWith({int? id, String? name, DateTime? birthday, int? nextUser}) =>
User(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
);
@override
@ -62,53 +74,64 @@ class User extends DataClass implements Insertable<User> {
return (StringBuffer('User(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, name, nextUser);
int get hashCode => Object.hash(id, name, birthday, nextUser);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is User &&
other.id == this.id &&
other.name == this.name &&
other.birthday == this.birthday &&
other.nextUser == this.nextUser);
}
class UsersCompanion extends UpdateCompanion<User> {
final Value<int> id;
final Value<String> name;
final Value<DateTime?> birthday;
final Value<int?> nextUser;
const UsersCompanion({
this.id = const Value.absent(),
this.name = const Value.absent(),
this.birthday = const Value.absent(),
this.nextUser = const Value.absent(),
});
UsersCompanion.insert({
this.id = const Value.absent(),
this.name = const Value.absent(),
this.birthday = const Value.absent(),
this.nextUser = const Value.absent(),
});
static Insertable<User> custom({
Expression<int>? id,
Expression<String>? name,
Expression<DateTime>? birthday,
Expression<int>? nextUser,
}) {
return RawValuesInsertable({
if (id != null) 'id': id,
if (name != null) 'name': name,
if (birthday != null) 'birthday': birthday,
if (nextUser != null) 'next_user': nextUser,
});
}
UsersCompanion copyWith(
{Value<int>? id, Value<String>? name, Value<int?>? nextUser}) {
{Value<int>? id,
Value<String>? name,
Value<DateTime?>? birthday,
Value<int?>? nextUser}) {
return UsersCompanion(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
);
}
@ -122,6 +145,9 @@ class UsersCompanion extends UpdateCompanion<User> {
if (name.present) {
map['name'] = Variable<String>(name.value);
}
if (birthday.present) {
map['birthday'] = Variable<DateTime>(birthday.value);
}
if (nextUser.present) {
map['next_user'] = Variable<int>(nextUser.value);
}
@ -133,6 +159,7 @@ class UsersCompanion extends UpdateCompanion<User> {
return (StringBuffer('UsersCompanion(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser')
..write(')'))
.toString();
@ -158,6 +185,11 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> {
type: DriftSqlType.string,
requiredDuringInsert: false,
defaultValue: const Constant('name'));
final VerificationMeta _birthdayMeta = const VerificationMeta('birthday');
@override
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime, requiredDuringInsert: false);
final VerificationMeta _nextUserMeta = const VerificationMeta('nextUser');
@override
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
@ -166,7 +198,7 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> {
requiredDuringInsert: false,
defaultConstraints: 'REFERENCES users (id)');
@override
List<GeneratedColumn> get $columns => [id, name, nextUser];
List<GeneratedColumn> get $columns => [id, name, birthday, nextUser];
@override
String get aliasedName => _alias ?? 'users';
@override
@ -183,6 +215,10 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> {
context.handle(
_nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta));
}
if (data.containsKey('birthday')) {
context.handle(_birthdayMeta,
birthday.isAcceptableOrUnknown(data['birthday']!, _birthdayMeta));
}
if (data.containsKey('next_user')) {
context.handle(_nextUserMeta,
nextUser.isAcceptableOrUnknown(data['next_user']!, _nextUserMeta));
@ -200,6 +236,8 @@ class $UsersTable extends Users with TableInfo<$UsersTable, User> {
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
name: attachedDatabase.options.types
.read(DriftSqlType.string, data['${effectivePrefix}name'])!,
birthday: attachedDatabase.options.types
.read(DriftSqlType.dateTime, data['${effectivePrefix}birthday']),
nextUser: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}next_user']),
);
@ -463,11 +501,13 @@ class Groups extends Table with TableInfo<Groups, Group> {
class GroupCountData extends DataClass {
final int id;
final String name;
final DateTime? birthday;
final int? nextUser;
final int groupCount;
const GroupCountData(
{required this.id,
required this.name,
this.birthday,
this.nextUser,
required this.groupCount});
factory GroupCountData.fromJson(Map<String, dynamic> json,
@ -476,6 +516,7 @@ class GroupCountData extends DataClass {
return GroupCountData(
id: serializer.fromJson<int>(json['id']),
name: serializer.fromJson<String>(json['name']),
birthday: serializer.fromJson<DateTime?>(json['birthday']),
nextUser: serializer.fromJson<int?>(json['nextUser']),
groupCount: serializer.fromJson<int>(json['groupCount']),
);
@ -486,16 +527,22 @@ class GroupCountData extends DataClass {
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'name': serializer.toJson<String>(name),
'birthday': serializer.toJson<DateTime?>(birthday),
'nextUser': serializer.toJson<int?>(nextUser),
'groupCount': serializer.toJson<int>(groupCount),
};
}
GroupCountData copyWith(
{int? id, String? name, int? nextUser, int? groupCount}) =>
{int? id,
String? name,
DateTime? birthday,
int? nextUser,
int? groupCount}) =>
GroupCountData(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
groupCount: groupCount ?? this.groupCount,
);
@ -504,6 +551,7 @@ class GroupCountData extends DataClass {
return (StringBuffer('GroupCountData(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser, ')
..write('groupCount: $groupCount')
..write(')'))
@ -511,13 +559,14 @@ class GroupCountData extends DataClass {
}
@override
int get hashCode => Object.hash(id, name, nextUser, groupCount);
int get hashCode => Object.hash(id, name, birthday, nextUser, groupCount);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is GroupCountData &&
other.id == this.id &&
other.name == this.name &&
other.birthday == this.birthday &&
other.nextUser == this.nextUser &&
other.groupCount == this.groupCount);
}
@ -529,7 +578,8 @@ class GroupCount extends ViewInfo<GroupCount, GroupCountData>
final _$Database attachedDatabase;
GroupCount(this.attachedDatabase, [this._alias]);
@override
List<GeneratedColumn> get $columns => [id, name, nextUser, groupCount];
List<GeneratedColumn> get $columns =>
[id, name, birthday, nextUser, groupCount];
@override
String get aliasedName => _alias ?? entityName;
@override
@ -547,6 +597,8 @@ class GroupCount extends ViewInfo<GroupCount, GroupCountData>
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
name: attachedDatabase.options.types
.read(DriftSqlType.string, data['${effectivePrefix}name'])!,
birthday: attachedDatabase.options.types
.read(DriftSqlType.dateTime, data['${effectivePrefix}birthday']),
nextUser: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}next_user']),
groupCount: attachedDatabase.options.types
@ -559,6 +611,9 @@ class GroupCount extends ViewInfo<GroupCount, GroupCountData>
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: DriftSqlType.string);
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime);
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
'next_user', aliasedName, true,
type: DriftSqlType.int);
@ -587,4 +642,7 @@ abstract class _$Database extends GeneratedDatabase {
@override
List<DatabaseSchemaEntity> get allSchemaEntities =>
[users, groups, groupCount];
@override
DriftDatabaseOptions get options =>
const DriftDatabaseOptions(storeDateTimeAsText: true);
}

View File

@ -2,6 +2,7 @@
//@dart=2.12
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations.dart';
import 'schema_v6.dart' as v6;
import 'schema_v2.dart' as v2;
import 'schema_v3.dart' as v3;
import 'schema_v4.dart' as v4;
@ -12,6 +13,8 @@ class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 6:
return v6.DatabaseAtV6(db);
case 2:
return v2.DatabaseAtV2(db);
case 3:
@ -23,7 +26,7 @@ class GeneratedHelper implements SchemaInstantiationHelper {
case 5:
return v5.DatabaseAtV5(db);
default:
throw MissingSchemaException(version, const {2, 3, 4, 1, 5});
throw MissingSchemaException(version, const {6, 2, 3, 4, 1, 5});
}
}
}

View File

@ -0,0 +1,162 @@
// GENERATED CODE, DO NOT EDIT BY HAND.
//@dart=2.12
import 'package:drift/drift.dart';
class Users extends Table with TableInfo {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Users(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: DriftSqlType.string,
requiredDuringInsert: false,
defaultValue: const Constant('name'));
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime, requiredDuringInsert: false);
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
'next_user', aliasedName, true,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'REFERENCES users (id)');
@override
List<GeneratedColumn> get $columns => [id, name, birthday, nextUser];
@override
String get aliasedName => _alias ?? 'users';
@override
String get actualTableName => 'users';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
Never map(Map<String, dynamic> data, {String? tablePrefix}) {
throw UnsupportedError('TableInfo.map in schema verification code');
}
@override
Users createAlias(String alias) {
return Users(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => false;
}
class Groups extends Table with TableInfo {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Groups(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: false,
$customConstraints: 'NOT NULL');
late final GeneratedColumn<String> title = GeneratedColumn<String>(
'title', aliasedName, false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL');
late final GeneratedColumn<bool> deleted = GeneratedColumn<bool>(
'deleted', aliasedName, true,
type: DriftSqlType.bool,
requiredDuringInsert: false,
$customConstraints: 'DEFAULT FALSE',
defaultValue: const CustomExpression<bool>('FALSE'));
late final GeneratedColumn<int> owner = GeneratedColumn<int>(
'owner', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL REFERENCES users (id)');
@override
List<GeneratedColumn> get $columns => [id, title, deleted, owner];
@override
String get aliasedName => _alias ?? 'groups';
@override
String get actualTableName => 'groups';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
Never map(Map<String, dynamic> data, {String? tablePrefix}) {
throw UnsupportedError('TableInfo.map in schema verification code');
}
@override
Groups createAlias(String alias) {
return Groups(attachedDatabase, alias);
}
@override
List<String> get customConstraints => const ['PRIMARY KEY (id)'];
@override
bool get dontWriteConstraints => true;
}
class GroupCount extends ViewInfo<GroupCount, Never> implements HasResultSet {
final String? _alias;
@override
final DatabaseAtV6 attachedDatabase;
GroupCount(this.attachedDatabase, [this._alias]);
@override
List<GeneratedColumn> get $columns =>
[id, name, birthday, nextUser, groupCount];
@override
String get aliasedName => _alias ?? entityName;
@override
String get entityName => 'group_count';
@override
String? get createViewStmt => null;
@override
GroupCount get asDslTable => this;
@override
Never map(Map<String, dynamic> data, {String? tablePrefix}) {
throw UnsupportedError('TableInfo.map in schema verification code');
}
late final GeneratedColumn<int> id =
GeneratedColumn<int>('id', aliasedName, false, type: DriftSqlType.int);
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: DriftSqlType.string);
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime);
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
'next_user', aliasedName, true,
type: DriftSqlType.int);
late final GeneratedColumn<int> groupCount = GeneratedColumn<int>(
'group_count', aliasedName, false,
type: DriftSqlType.int);
@override
GroupCount createAlias(String alias) {
return GroupCount(attachedDatabase, alias);
}
@override
Query? get query => null;
@override
Set<String> get readTables => const {};
}
class DatabaseAtV6 extends GeneratedDatabase {
DatabaseAtV6(QueryExecutor e) : super(e);
DatabaseAtV6.connect(DatabaseConnection c) : super.connect(c);
late final Users users = Users(this);
late final Groups groups = Groups(this);
late final GroupCount groupCount = GroupCount(this);
@override
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities =>
[users, groups, groupCount];
@override
int get schemaVersion => 6;
@override
DriftDatabaseOptions get options =>
const DriftDatabaseOptions(storeDateTimeAsText: true);
}

View File

@ -6,5 +6,8 @@ class Users extends Table {
// added in schema version 2, got a default in version 4
TextColumn get name => text().withDefault(const Constant('name'))();
// Column added in version 6
DateTimeColumn get birthday => dateTime().nullable()();
IntColumn get nextUser => integer().nullable().references(Users, #id)();
}

View File

@ -2,6 +2,7 @@
//@dart=2.12
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations.dart';
import 'schema_v6.dart' as v6;
import 'schema_v2.dart' as v2;
import 'schema_v3.dart' as v3;
import 'schema_v4.dart' as v4;
@ -12,6 +13,8 @@ class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 6:
return v6.DatabaseAtV6(db);
case 2:
return v2.DatabaseAtV2(db);
case 3:
@ -23,7 +26,7 @@ class GeneratedHelper implements SchemaInstantiationHelper {
case 5:
return v5.DatabaseAtV5(db);
default:
throw MissingSchemaException(version, const {2, 3, 4, 1, 5});
throw MissingSchemaException(version, const {6, 2, 3, 4, 1, 5});
}
}
}

View File

@ -4,7 +4,7 @@ import 'package:drift/drift.dart';
class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
UsersData({required this.id});
const UsersData({required this.id});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};

View File

@ -5,7 +5,7 @@ import 'package:drift/drift.dart';
class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
final String name;
UsersData({required this.id, required this.name});
const UsersData({required this.id, required this.name});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};

View File

@ -5,7 +5,7 @@ import 'package:drift/drift.dart';
class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
final String name;
UsersData({required this.id, required this.name});
const UsersData({required this.id, required this.name});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
@ -155,7 +155,7 @@ class GroupsData extends DataClass implements Insertable<GroupsData> {
final String title;
final bool? deleted;
final int owner;
GroupsData(
const GroupsData(
{required this.id,
required this.title,
this.deleted,

View File

@ -5,7 +5,7 @@ import 'package:drift/drift.dart';
class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
final String name;
UsersData({required this.id, required this.name});
const UsersData({required this.id, required this.name});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
@ -157,7 +157,7 @@ class GroupsData extends DataClass implements Insertable<GroupsData> {
final String title;
final bool? deleted;
final int owner;
GroupsData(
const GroupsData(
{required this.id,
required this.title,
this.deleted,

View File

@ -6,7 +6,7 @@ class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
final String name;
final int? nextUser;
UsersData({required this.id, required this.name, this.nextUser});
const UsersData({required this.id, required this.name, this.nextUser});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
@ -189,7 +189,7 @@ class GroupsData extends DataClass implements Insertable<GroupsData> {
final String title;
final bool? deleted;
final int owner;
GroupsData(
const GroupsData(
{required this.id,
required this.title,
this.deleted,
@ -408,7 +408,7 @@ class GroupCountData extends DataClass {
final String name;
final int? nextUser;
final int groupCount;
GroupCountData(
const GroupCountData(
{required this.id,
required this.name,
this.nextUser,

View File

@ -0,0 +1,587 @@
// GENERATED CODE, DO NOT EDIT BY HAND.
//@dart=2.12
import 'package:drift/drift.dart';
class UsersData extends DataClass implements Insertable<UsersData> {
final int id;
final String name;
final DateTime? birthday;
final int? nextUser;
const UsersData(
{required this.id, required this.name, this.birthday, this.nextUser});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<int>(id);
map['name'] = Variable<String>(name);
if (!nullToAbsent || birthday != null) {
map['birthday'] = Variable<DateTime>(birthday);
}
if (!nullToAbsent || nextUser != null) {
map['next_user'] = Variable<int>(nextUser);
}
return map;
}
UsersCompanion toCompanion(bool nullToAbsent) {
return UsersCompanion(
id: Value(id),
name: Value(name),
birthday: birthday == null && nullToAbsent
? const Value.absent()
: Value(birthday),
nextUser: nextUser == null && nullToAbsent
? const Value.absent()
: Value(nextUser),
);
}
factory UsersData.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return UsersData(
id: serializer.fromJson<int>(json['id']),
name: serializer.fromJson<String>(json['name']),
birthday: serializer.fromJson<DateTime?>(json['birthday']),
nextUser: serializer.fromJson<int?>(json['nextUser']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'name': serializer.toJson<String>(name),
'birthday': serializer.toJson<DateTime?>(birthday),
'nextUser': serializer.toJson<int?>(nextUser),
};
}
UsersData copyWith(
{int? id, String? name, DateTime? birthday, int? nextUser}) =>
UsersData(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
);
@override
String toString() {
return (StringBuffer('UsersData(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, name, birthday, nextUser);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is UsersData &&
other.id == this.id &&
other.name == this.name &&
other.birthday == this.birthday &&
other.nextUser == this.nextUser);
}
class UsersCompanion extends UpdateCompanion<UsersData> {
final Value<int> id;
final Value<String> name;
final Value<DateTime?> birthday;
final Value<int?> nextUser;
const UsersCompanion({
this.id = const Value.absent(),
this.name = const Value.absent(),
this.birthday = const Value.absent(),
this.nextUser = const Value.absent(),
});
UsersCompanion.insert({
this.id = const Value.absent(),
this.name = const Value.absent(),
this.birthday = const Value.absent(),
this.nextUser = const Value.absent(),
});
static Insertable<UsersData> custom({
Expression<int>? id,
Expression<String>? name,
Expression<DateTime>? birthday,
Expression<int>? nextUser,
}) {
return RawValuesInsertable({
if (id != null) 'id': id,
if (name != null) 'name': name,
if (birthday != null) 'birthday': birthday,
if (nextUser != null) 'next_user': nextUser,
});
}
UsersCompanion copyWith(
{Value<int>? id,
Value<String>? name,
Value<DateTime?>? birthday,
Value<int?>? nextUser}) {
return UsersCompanion(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (id.present) {
map['id'] = Variable<int>(id.value);
}
if (name.present) {
map['name'] = Variable<String>(name.value);
}
if (birthday.present) {
map['birthday'] = Variable<DateTime>(birthday.value);
}
if (nextUser.present) {
map['next_user'] = Variable<int>(nextUser.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('UsersCompanion(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser')
..write(')'))
.toString();
}
}
class Users extends Table with TableInfo<Users, UsersData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Users(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'PRIMARY KEY AUTOINCREMENT');
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: DriftSqlType.string,
requiredDuringInsert: false,
defaultValue: const Constant('name'));
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime, requiredDuringInsert: false);
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
'next_user', aliasedName, true,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultConstraints: 'REFERENCES users (id)');
@override
List<GeneratedColumn> get $columns => [id, name, birthday, nextUser];
@override
String get aliasedName => _alias ?? 'users';
@override
String get actualTableName => 'users';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
UsersData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return UsersData(
id: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
name: attachedDatabase.options.types
.read(DriftSqlType.string, data['${effectivePrefix}name'])!,
birthday: attachedDatabase.options.types
.read(DriftSqlType.dateTime, data['${effectivePrefix}birthday']),
nextUser: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}next_user']),
);
}
@override
Users createAlias(String alias) {
return Users(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => false;
}
class GroupsData extends DataClass implements Insertable<GroupsData> {
final int id;
final String title;
final bool? deleted;
final int owner;
const GroupsData(
{required this.id,
required this.title,
this.deleted,
required this.owner});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<int>(id);
map['title'] = Variable<String>(title);
if (!nullToAbsent || deleted != null) {
map['deleted'] = Variable<bool>(deleted);
}
map['owner'] = Variable<int>(owner);
return map;
}
GroupsCompanion toCompanion(bool nullToAbsent) {
return GroupsCompanion(
id: Value(id),
title: Value(title),
deleted: deleted == null && nullToAbsent
? const Value.absent()
: Value(deleted),
owner: Value(owner),
);
}
factory GroupsData.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return GroupsData(
id: serializer.fromJson<int>(json['id']),
title: serializer.fromJson<String>(json['title']),
deleted: serializer.fromJson<bool?>(json['deleted']),
owner: serializer.fromJson<int>(json['owner']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'title': serializer.toJson<String>(title),
'deleted': serializer.toJson<bool?>(deleted),
'owner': serializer.toJson<int>(owner),
};
}
GroupsData copyWith({int? id, String? title, bool? deleted, int? owner}) =>
GroupsData(
id: id ?? this.id,
title: title ?? this.title,
deleted: deleted ?? this.deleted,
owner: owner ?? this.owner,
);
@override
String toString() {
return (StringBuffer('GroupsData(')
..write('id: $id, ')
..write('title: $title, ')
..write('deleted: $deleted, ')
..write('owner: $owner')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, title, deleted, owner);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is GroupsData &&
other.id == this.id &&
other.title == this.title &&
other.deleted == this.deleted &&
other.owner == this.owner);
}
class GroupsCompanion extends UpdateCompanion<GroupsData> {
final Value<int> id;
final Value<String> title;
final Value<bool?> deleted;
final Value<int> owner;
const GroupsCompanion({
this.id = const Value.absent(),
this.title = const Value.absent(),
this.deleted = const Value.absent(),
this.owner = const Value.absent(),
});
GroupsCompanion.insert({
this.id = const Value.absent(),
required String title,
this.deleted = const Value.absent(),
required int owner,
}) : title = Value(title),
owner = Value(owner);
static Insertable<GroupsData> custom({
Expression<int>? id,
Expression<String>? title,
Expression<bool>? deleted,
Expression<int>? owner,
}) {
return RawValuesInsertable({
if (id != null) 'id': id,
if (title != null) 'title': title,
if (deleted != null) 'deleted': deleted,
if (owner != null) 'owner': owner,
});
}
GroupsCompanion copyWith(
{Value<int>? id,
Value<String>? title,
Value<bool?>? deleted,
Value<int>? owner}) {
return GroupsCompanion(
id: id ?? this.id,
title: title ?? this.title,
deleted: deleted ?? this.deleted,
owner: owner ?? this.owner,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (id.present) {
map['id'] = Variable<int>(id.value);
}
if (title.present) {
map['title'] = Variable<String>(title.value);
}
if (deleted.present) {
map['deleted'] = Variable<bool>(deleted.value);
}
if (owner.present) {
map['owner'] = Variable<int>(owner.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('GroupsCompanion(')
..write('id: $id, ')
..write('title: $title, ')
..write('deleted: $deleted, ')
..write('owner: $owner')
..write(')'))
.toString();
}
}
class Groups extends Table with TableInfo<Groups, GroupsData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Groups(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> id = GeneratedColumn<int>(
'id', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: false,
$customConstraints: 'NOT NULL');
late final GeneratedColumn<String> title = GeneratedColumn<String>(
'title', aliasedName, false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL');
late final GeneratedColumn<bool> deleted = GeneratedColumn<bool>(
'deleted', aliasedName, true,
type: DriftSqlType.bool,
requiredDuringInsert: false,
$customConstraints: 'DEFAULT FALSE',
defaultValue: const CustomExpression<bool>('FALSE'));
late final GeneratedColumn<int> owner = GeneratedColumn<int>(
'owner', aliasedName, false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL REFERENCES users (id)');
@override
List<GeneratedColumn> get $columns => [id, title, deleted, owner];
@override
String get aliasedName => _alias ?? 'groups';
@override
String get actualTableName => 'groups';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
GroupsData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return GroupsData(
id: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
title: attachedDatabase.options.types
.read(DriftSqlType.string, data['${effectivePrefix}title'])!,
deleted: attachedDatabase.options.types
.read(DriftSqlType.bool, data['${effectivePrefix}deleted']),
owner: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}owner'])!,
);
}
@override
Groups createAlias(String alias) {
return Groups(attachedDatabase, alias);
}
@override
List<String> get customConstraints => const ['PRIMARY KEY (id)'];
@override
bool get dontWriteConstraints => true;
}
class GroupCountData extends DataClass {
final int id;
final String name;
final DateTime? birthday;
final int? nextUser;
final int groupCount;
const GroupCountData(
{required this.id,
required this.name,
this.birthday,
this.nextUser,
required this.groupCount});
factory GroupCountData.fromJson(Map<String, dynamic> json,
{ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return GroupCountData(
id: serializer.fromJson<int>(json['id']),
name: serializer.fromJson<String>(json['name']),
birthday: serializer.fromJson<DateTime?>(json['birthday']),
nextUser: serializer.fromJson<int?>(json['nextUser']),
groupCount: serializer.fromJson<int>(json['groupCount']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<int>(id),
'name': serializer.toJson<String>(name),
'birthday': serializer.toJson<DateTime?>(birthday),
'nextUser': serializer.toJson<int?>(nextUser),
'groupCount': serializer.toJson<int>(groupCount),
};
}
GroupCountData copyWith(
{int? id,
String? name,
DateTime? birthday,
int? nextUser,
int? groupCount}) =>
GroupCountData(
id: id ?? this.id,
name: name ?? this.name,
birthday: birthday ?? this.birthday,
nextUser: nextUser ?? this.nextUser,
groupCount: groupCount ?? this.groupCount,
);
@override
String toString() {
return (StringBuffer('GroupCountData(')
..write('id: $id, ')
..write('name: $name, ')
..write('birthday: $birthday, ')
..write('nextUser: $nextUser, ')
..write('groupCount: $groupCount')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, name, birthday, nextUser, groupCount);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is GroupCountData &&
other.id == this.id &&
other.name == this.name &&
other.birthday == this.birthday &&
other.nextUser == this.nextUser &&
other.groupCount == this.groupCount);
}
class GroupCount extends ViewInfo<GroupCount, GroupCountData>
implements HasResultSet {
final String? _alias;
@override
final DatabaseAtV6 attachedDatabase;
GroupCount(this.attachedDatabase, [this._alias]);
@override
List<GeneratedColumn> get $columns =>
[id, name, birthday, nextUser, groupCount];
@override
String get aliasedName => _alias ?? entityName;
@override
String get entityName => 'group_count';
@override
String? get createViewStmt => null;
@override
GroupCount get asDslTable => this;
@override
GroupCountData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return GroupCountData(
id: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}id'])!,
name: attachedDatabase.options.types
.read(DriftSqlType.string, data['${effectivePrefix}name'])!,
birthday: attachedDatabase.options.types
.read(DriftSqlType.dateTime, data['${effectivePrefix}birthday']),
nextUser: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}next_user']),
groupCount: attachedDatabase.options.types
.read(DriftSqlType.int, data['${effectivePrefix}group_count'])!,
);
}
late final GeneratedColumn<int> id =
GeneratedColumn<int>('id', aliasedName, false, type: DriftSqlType.int);
late final GeneratedColumn<String> name = GeneratedColumn<String>(
'name', aliasedName, false,
type: DriftSqlType.string);
late final GeneratedColumn<DateTime> birthday = GeneratedColumn<DateTime>(
'birthday', aliasedName, true,
type: DriftSqlType.dateTime);
late final GeneratedColumn<int> nextUser = GeneratedColumn<int>(
'next_user', aliasedName, true,
type: DriftSqlType.int);
late final GeneratedColumn<int> groupCount = GeneratedColumn<int>(
'group_count', aliasedName, false,
type: DriftSqlType.int);
@override
GroupCount createAlias(String alias) {
return GroupCount(attachedDatabase, alias);
}
@override
Query? get query => null;
@override
Set<String> get readTables => const {};
}
class DatabaseAtV6 extends GeneratedDatabase {
DatabaseAtV6(QueryExecutor e) : super(e);
DatabaseAtV6.connect(DatabaseConnection c) : super.connect(c);
late final Users users = Users(this);
late final Groups groups = Groups(this);
late final GroupCount groupCount = GroupCount(this);
@override
Iterable<TableInfo> get allTables => allSchemaEntities.whereType<TableInfo>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities =>
[users, groups, groupCount];
@override
int get schemaVersion => 6;
@override
DriftDatabaseOptions get options =>
const DriftDatabaseOptions(storeDateTimeAsText: true);
}

View File

@ -98,4 +98,12 @@ void main() {
.having((e) => e.groupCount, 'groupCount', 0)));
await migratedDb.close();
});
test('upgrade from v5 to v6', () async {
final connection = await verifier.startAt(5);
final db = Database(connection);
addTearDown(db.close);
await verifier.migrateAndValidate(db, 6);
});
}