mirror of https://github.com/AMT-Cheif/drift.git
Make schema classes public (#2749)
This commit is contained in:
parent
81d7e92d30
commit
434982ac85
|
@ -3,8 +3,8 @@ import 'package:drift/drift.dart' as i1;
|
|||
import 'package:drift/drift.dart'; // ignore_for_file: type=lint,unused_import
|
||||
|
||||
// GENERATED BY drift_dev, DO NOT MODIFY.
|
||||
final class _S2 extends i0.VersionedSchema {
|
||||
_S2({required super.database}) : super(version: 2);
|
||||
final class Schema2 extends i0.VersionedSchema {
|
||||
Schema2({required super.database}) : super(version: 2);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
todos,
|
||||
|
@ -62,8 +62,8 @@ i1.GeneratedColumn<DateTime> _column_4(String aliasedName) =>
|
|||
i1.GeneratedColumn<DateTime>('due_date', aliasedName, true,
|
||||
type: i1.DriftSqlType.dateTime);
|
||||
|
||||
final class _S3 extends i0.VersionedSchema {
|
||||
_S3({required super.database}) : super(version: 3);
|
||||
final class Schema3 extends i0.VersionedSchema {
|
||||
Schema3({required super.database}) : super(version: 3);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
todos,
|
||||
|
@ -107,18 +107,18 @@ i1.GeneratedColumn<int> _column_5(String aliasedName) =>
|
|||
i1.GeneratedColumn<int>('priority', aliasedName, true,
|
||||
type: i1.DriftSqlType.int);
|
||||
i0.MigrationStepWithVersion migrationSteps({
|
||||
required Future<void> Function(i1.Migrator m, _S2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, _S3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
|
||||
}) {
|
||||
return (currentVersion, database) async {
|
||||
switch (currentVersion) {
|
||||
case 1:
|
||||
final schema = _S2(database: database);
|
||||
final schema = Schema2(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from1To2(migrator, schema);
|
||||
return 2;
|
||||
case 2:
|
||||
final schema = _S3(database: database);
|
||||
final schema = Schema3(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from2To3(migrator, schema);
|
||||
return 3;
|
||||
|
@ -129,8 +129,8 @@ i0.MigrationStepWithVersion migrationSteps({
|
|||
}
|
||||
|
||||
i1.OnUpgrade stepByStep({
|
||||
required Future<void> Function(i1.Migrator m, _S2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, _S3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
|
||||
}) =>
|
||||
i0.VersionedSchema.stepByStepHelper(
|
||||
step: migrationSteps(
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
of the Dart table name now supports more forms of plurals.
|
||||
For instance, a table without a `@DataClassName` annotation named `Categories`
|
||||
would now generate a `Category` class instead of `Categorie`.
|
||||
- Make versioned schema snapshots generated by `drift_dev schema steps` public.
|
||||
- Don't generate `const` row classes when they are extending a class which
|
||||
isn't const.
|
||||
|
||||
|
|
|
@ -75,6 +75,10 @@ class SchemaVersionWriter {
|
|||
assert(versions.isSortedBy<num>((element) => element.version));
|
||||
}
|
||||
|
||||
String _nameForSchemaClass(int version) {
|
||||
return 'Schema$version';
|
||||
}
|
||||
|
||||
/// Since not every column changes in every schema version, we prefer to re-use
|
||||
/// columns with an identical definition across tables and schema versions.
|
||||
///
|
||||
|
@ -308,7 +312,7 @@ class SchemaVersionWriter {
|
|||
text
|
||||
..write('required Future<void> Function(')
|
||||
..writeDriftRef('Migrator')
|
||||
..write(' m, _S${next.version} schema)')
|
||||
..write(' m, ${_nameForSchemaClass(next.version)} schema)')
|
||||
..writeln('from${current.version}To${next.version},');
|
||||
}
|
||||
}
|
||||
|
@ -322,7 +326,7 @@ class SchemaVersionWriter {
|
|||
// only need them for versions targeted by migrations.
|
||||
for (final version in versions.skip(1)) {
|
||||
final versionNo = version.version;
|
||||
final versionClass = '_S$versionNo';
|
||||
final versionClass = _nameForSchemaClass(version.version);
|
||||
final versionScope = libraryScope.child();
|
||||
|
||||
// Reserve all the names already in use in [VersionedSchema] and its
|
||||
|
@ -336,7 +340,7 @@ class SchemaVersionWriter {
|
|||
'runMigrationSteps',
|
||||
]);
|
||||
|
||||
// Write an _S<x> class for each schema version x.
|
||||
// Write an Schema<x> class for each schema version x.
|
||||
versionScope.leaf()
|
||||
..write('final class $versionClass extends ')
|
||||
..writeUriRef(_schemaLibrary, 'VersionedSchema')
|
||||
|
@ -367,7 +371,7 @@ class SchemaVersionWriter {
|
|||
// Write a MigrationStepWithVersion factory that takes a callback doing a
|
||||
// step for each schema to to the next. We supply a special migrator that
|
||||
// only considers entities from that version, as well as a typed reference
|
||||
// to the _S<x> class used to lookup elements.
|
||||
// to the numbered Schema<x> class used to lookup elements.
|
||||
final steps = libraryScope.leaf()
|
||||
..writeUriRef(_schemaLibrary, 'MigrationStepWithVersion')
|
||||
..write(' migrationSteps({');
|
||||
|
@ -380,7 +384,8 @@ class SchemaVersionWriter {
|
|||
for (final (current, next) in versions.withNext) {
|
||||
steps
|
||||
..writeln('case ${current.version}:')
|
||||
..write('final schema = _S${next.version}(database: database);')
|
||||
..write(
|
||||
'final schema = ${_nameForSchemaClass(next.version)}(database: database);')
|
||||
..write('final migrator = ')
|
||||
..writeDriftRef('Migrator')
|
||||
..writeln('(database, schema);')
|
||||
|
|
|
@ -3,8 +3,8 @@ import 'package:drift/drift.dart' as i1;
|
|||
import 'package:drift/drift.dart'; // ignore_for_file: type=lint,unused_import
|
||||
|
||||
// GENERATED BY drift_dev, DO NOT MODIFY.
|
||||
final class _S2 extends i0.VersionedSchema {
|
||||
_S2({required super.database}) : super(version: 2);
|
||||
final class Schema2 extends i0.VersionedSchema {
|
||||
Schema2({required super.database}) : super(version: 2);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -42,8 +42,8 @@ i1.GeneratedColumn<String> _column_1(String aliasedName) =>
|
|||
i1.GeneratedColumn<String>('name', aliasedName, false,
|
||||
type: i1.DriftSqlType.string);
|
||||
|
||||
final class _S3 extends i0.VersionedSchema {
|
||||
_S3({required super.database}) : super(version: 3);
|
||||
final class Schema3 extends i0.VersionedSchema {
|
||||
Schema3({required super.database}) : super(version: 3);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -109,8 +109,8 @@ i1.GeneratedColumn<int> _column_5(String aliasedName) =>
|
|||
type: i1.DriftSqlType.int,
|
||||
$customConstraints: 'NOT NULL REFERENCES users (id)');
|
||||
|
||||
final class _S4 extends i0.VersionedSchema {
|
||||
_S4({required super.database}) : super(version: 4);
|
||||
final class Schema4 extends i0.VersionedSchema {
|
||||
Schema4({required super.database}) : super(version: 4);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -152,8 +152,8 @@ i1.GeneratedColumn<String> _column_6(String aliasedName) =>
|
|||
i1.GeneratedColumn<String>('name', aliasedName, false,
|
||||
type: i1.DriftSqlType.string, defaultValue: const Constant('name'));
|
||||
|
||||
final class _S5 extends i0.VersionedSchema {
|
||||
_S5({required super.database}) : super(version: 5);
|
||||
final class Schema5 extends i0.VersionedSchema {
|
||||
Schema5({required super.database}) : super(version: 5);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -245,8 +245,8 @@ i1.GeneratedColumn<int> _column_10(String aliasedName) =>
|
|||
i1.GeneratedColumn<int>('group_count', aliasedName, false,
|
||||
type: i1.DriftSqlType.int);
|
||||
|
||||
final class _S6 extends i0.VersionedSchema {
|
||||
_S6({required super.database}) : super(version: 6);
|
||||
final class Schema6 extends i0.VersionedSchema {
|
||||
Schema6({required super.database}) : super(version: 6);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -332,8 +332,8 @@ class Shape5 extends i0.VersionedView {
|
|||
columnsByName['group_count']! as i1.GeneratedColumn<int>;
|
||||
}
|
||||
|
||||
final class _S7 extends i0.VersionedSchema {
|
||||
_S7({required super.database}) : super(version: 7);
|
||||
final class Schema7 extends i0.VersionedSchema {
|
||||
Schema7({required super.database}) : super(version: 7);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -423,8 +423,8 @@ i1.GeneratedColumn<String> _column_14(String aliasedName) =>
|
|||
i1.GeneratedColumn<String>('search_terms', aliasedName, false,
|
||||
type: i1.DriftSqlType.string, $customConstraints: '');
|
||||
|
||||
final class _S8 extends i0.VersionedSchema {
|
||||
_S8({required super.database}) : super(version: 8);
|
||||
final class Schema8 extends i0.VersionedSchema {
|
||||
Schema8({required super.database}) : super(version: 8);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -502,8 +502,8 @@ i1.GeneratedColumn<int> _column_15(String aliasedName) =>
|
|||
defaultConstraints:
|
||||
i1.GeneratedColumn.constraintIsAlways('REFERENCES "users" ("id")'));
|
||||
|
||||
final class _S9 extends i0.VersionedSchema {
|
||||
_S9({required super.database}) : super(version: 9);
|
||||
final class Schema9 extends i0.VersionedSchema {
|
||||
Schema9({required super.database}) : super(version: 9);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -586,8 +586,8 @@ i1.GeneratedColumn<int> _column_17(String aliasedName) =>
|
|||
type: i1.DriftSqlType.int,
|
||||
$customConstraints: 'NOT NULL REFERENCES users(id)');
|
||||
|
||||
final class _S10 extends i0.VersionedSchema {
|
||||
_S10({required super.database}) : super(version: 10);
|
||||
final class Schema10 extends i0.VersionedSchema {
|
||||
Schema10({required super.database}) : super(version: 10);
|
||||
@override
|
||||
late final List<i1.DatabaseSchemaEntity> entities = [
|
||||
users,
|
||||
|
@ -664,60 +664,60 @@ final class _S10 extends i0.VersionedSchema {
|
|||
}
|
||||
|
||||
i0.MigrationStepWithVersion migrationSteps({
|
||||
required Future<void> Function(i1.Migrator m, _S2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, _S3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, _S4 schema) from3To4,
|
||||
required Future<void> Function(i1.Migrator m, _S5 schema) from4To5,
|
||||
required Future<void> Function(i1.Migrator m, _S6 schema) from5To6,
|
||||
required Future<void> Function(i1.Migrator m, _S7 schema) from6To7,
|
||||
required Future<void> Function(i1.Migrator m, _S8 schema) from7To8,
|
||||
required Future<void> Function(i1.Migrator m, _S9 schema) from8To9,
|
||||
required Future<void> Function(i1.Migrator m, _S10 schema) from9To10,
|
||||
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
|
||||
required Future<void> Function(i1.Migrator m, Schema5 schema) from4To5,
|
||||
required Future<void> Function(i1.Migrator m, Schema6 schema) from5To6,
|
||||
required Future<void> Function(i1.Migrator m, Schema7 schema) from6To7,
|
||||
required Future<void> Function(i1.Migrator m, Schema8 schema) from7To8,
|
||||
required Future<void> Function(i1.Migrator m, Schema9 schema) from8To9,
|
||||
required Future<void> Function(i1.Migrator m, Schema10 schema) from9To10,
|
||||
}) {
|
||||
return (currentVersion, database) async {
|
||||
switch (currentVersion) {
|
||||
case 1:
|
||||
final schema = _S2(database: database);
|
||||
final schema = Schema2(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from1To2(migrator, schema);
|
||||
return 2;
|
||||
case 2:
|
||||
final schema = _S3(database: database);
|
||||
final schema = Schema3(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from2To3(migrator, schema);
|
||||
return 3;
|
||||
case 3:
|
||||
final schema = _S4(database: database);
|
||||
final schema = Schema4(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from3To4(migrator, schema);
|
||||
return 4;
|
||||
case 4:
|
||||
final schema = _S5(database: database);
|
||||
final schema = Schema5(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from4To5(migrator, schema);
|
||||
return 5;
|
||||
case 5:
|
||||
final schema = _S6(database: database);
|
||||
final schema = Schema6(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from5To6(migrator, schema);
|
||||
return 6;
|
||||
case 6:
|
||||
final schema = _S7(database: database);
|
||||
final schema = Schema7(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from6To7(migrator, schema);
|
||||
return 7;
|
||||
case 7:
|
||||
final schema = _S8(database: database);
|
||||
final schema = Schema8(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from7To8(migrator, schema);
|
||||
return 8;
|
||||
case 8:
|
||||
final schema = _S9(database: database);
|
||||
final schema = Schema9(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from8To9(migrator, schema);
|
||||
return 9;
|
||||
case 9:
|
||||
final schema = _S10(database: database);
|
||||
final schema = Schema10(database: database);
|
||||
final migrator = i1.Migrator(database, schema);
|
||||
await from9To10(migrator, schema);
|
||||
return 10;
|
||||
|
@ -728,15 +728,15 @@ i0.MigrationStepWithVersion migrationSteps({
|
|||
}
|
||||
|
||||
i1.OnUpgrade stepByStep({
|
||||
required Future<void> Function(i1.Migrator m, _S2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, _S3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, _S4 schema) from3To4,
|
||||
required Future<void> Function(i1.Migrator m, _S5 schema) from4To5,
|
||||
required Future<void> Function(i1.Migrator m, _S6 schema) from5To6,
|
||||
required Future<void> Function(i1.Migrator m, _S7 schema) from6To7,
|
||||
required Future<void> Function(i1.Migrator m, _S8 schema) from7To8,
|
||||
required Future<void> Function(i1.Migrator m, _S9 schema) from8To9,
|
||||
required Future<void> Function(i1.Migrator m, _S10 schema) from9To10,
|
||||
required Future<void> Function(i1.Migrator m, Schema2 schema) from1To2,
|
||||
required Future<void> Function(i1.Migrator m, Schema3 schema) from2To3,
|
||||
required Future<void> Function(i1.Migrator m, Schema4 schema) from3To4,
|
||||
required Future<void> Function(i1.Migrator m, Schema5 schema) from4To5,
|
||||
required Future<void> Function(i1.Migrator m, Schema6 schema) from5To6,
|
||||
required Future<void> Function(i1.Migrator m, Schema7 schema) from6To7,
|
||||
required Future<void> Function(i1.Migrator m, Schema8 schema) from7To8,
|
||||
required Future<void> Function(i1.Migrator m, Schema9 schema) from8To9,
|
||||
required Future<void> Function(i1.Migrator m, Schema10 schema) from9To10,
|
||||
}) =>
|
||||
i0.VersionedSchema.stepByStepHelper(
|
||||
step: migrationSteps(
|
||||
|
|
Loading…
Reference in New Issue