prepare for multiple apps

This commit is contained in:
Fabian Freund
2026-04-06 12:23:11 +02:00
parent bd1600e8dc
commit 5afc323f04
904 changed files with 29 additions and 29 deletions
@@ -0,0 +1,33 @@
// dart format width=80
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
import 'package:drift/internal/migrations.dart';
import 'schema_v1.dart' as v1;
import 'schema_v2.dart' as v2;
import 'schema_v3.dart' as v3;
import 'schema_v4.dart' as v4;
import 'schema_v5.dart' as v5;
class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 1:
return v1.DatabaseAtV1(db);
case 2:
return v2.DatabaseAtV2(db);
case 3:
return v3.DatabaseAtV3(db);
case 4:
return v4.DatabaseAtV4(db);
case 5:
return v5.DatabaseAtV5(db);
default:
throw MissingSchemaException(version, versions);
}
}
static const versions = const [1, 2, 3, 4, 5];
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// dart format width=80
// ignore_for_file: unused_local_variable, unused_import
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations_native.dart';
import 'package:weblibre/features/bangs/data/database/database.dart';
import 'package:flutter_test/flutter_test.dart';
import 'generated/schema.dart';
import 'generated/schema_v1.dart' as v1;
import 'generated/schema_v2.dart' as v2;
void main() {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
late SchemaVerifier verifier;
setUpAll(() {
verifier = SchemaVerifier(GeneratedHelper());
});
group('simple database migrations', () {
// These simple tests verify all possible schema updates with a simple (no
// data) migration. This is a quick way to ensure that written database
// migrations properly alter the schema.
const versions = GeneratedHelper.versions;
for (final (i, fromVersion) in versions.indexed) {
group('from $fromVersion', () {
for (final toVersion in versions.skip(i + 1)) {
test('to $toVersion', () async {
final schema = await verifier.schemaAt(fromVersion);
final db = BangDatabase(schema.newConnection());
await verifier.migrateAndValidate(db, toVersion);
await db.close();
});
}
});
}
});
// The following template shows how to write tests ensuring your migrations
// preserve existing data.
// Testing this can be useful for migrations that change existing columns
// (e.g. by alterating their type or constraints). Migrations that only add
// tables or columns typically don't need these advanced tests. For more
// information, see https://drift.simonbinder.eu/migrations/tests/#verifying-data-integrity
// TODO: This generated template shows how these tests could be written. Adopt
// it to your own needs when testing migrations with data integrity.
test('migration from v1 to v2 does not corrupt data', () async {
// Add data to insert into the old database, and the expected rows after the
// migration.
// TODO: Fill these lists
final oldBangData = <v1.BangData>[];
final expectedNewBangData = <v2.BangData>[];
final oldBangSyncData = <v1.BangSyncData>[];
final expectedNewBangSyncData = <v2.BangSyncData>[];
final oldBangFrequencyData = <v1.BangFrequencyData>[];
final expectedNewBangFrequencyData = <v2.BangFrequencyData>[];
final oldBangHistoryData = <v1.BangHistoryData>[];
final expectedNewBangHistoryData = <v2.BangHistoryData>[];
final oldBangFtsData = <v1.BangFtsData>[];
final expectedNewBangFtsData = <v2.BangFtsData>[];
await verifier.testWithDataIntegrity(
oldVersion: 1,
newVersion: 2,
createOld: v1.DatabaseAtV1.new,
createNew: v2.DatabaseAtV2.new,
openTestedDatabase: BangDatabase.new,
createItems: (batch, oldDb) {
batch.insertAll(oldDb.bang, oldBangData);
batch.insertAll(oldDb.bangSync, oldBangSyncData);
batch.insertAll(oldDb.bangFrequency, oldBangFrequencyData);
batch.insertAll(oldDb.bangHistory, oldBangHistoryData);
batch.insertAll(oldDb.bangFts, oldBangFtsData);
},
validateItems: (newDb) async {
expect(expectedNewBangData, await newDb.select(newDb.bang).get());
expect(
expectedNewBangSyncData,
await newDb.select(newDb.bangSync).get(),
);
expect(
expectedNewBangFrequencyData,
await newDb.select(newDb.bangFrequency).get(),
);
expect(
expectedNewBangHistoryData,
await newDb.select(newDb.bangHistory).get(),
);
expect(expectedNewBangFtsData, await newDb.select(newDb.bangFts).get());
},
);
});
}
@@ -0,0 +1,36 @@
// dart format width=80
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
import 'package:drift/internal/migrations.dart';
import 'schema_v2.dart' as v2;
import 'schema_v3.dart' as v3;
import 'schema_v4.dart' as v4;
import 'schema_v5.dart' as v5;
import 'schema_v6.dart' as v6;
import 'schema_v7.dart' as v7;
class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 2:
return v2.DatabaseAtV2(db);
case 3:
return v3.DatabaseAtV3(db);
case 4:
return v4.DatabaseAtV4(db);
case 5:
return v5.DatabaseAtV5(db);
case 6:
return v6.DatabaseAtV6(db);
case 7:
return v7.DatabaseAtV7(db);
default:
throw MissingSchemaException(version, versions);
}
}
static const versions = const [2, 3, 4, 5, 6, 7];
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,81 @@
// dart format width=80
// ignore_for_file: unused_local_variable, unused_import
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations_native.dart';
import 'package:weblibre/features/geckoview/features/tabs/data/database/database.dart';
import 'package:flutter_test/flutter_test.dart';
import 'generated/schema.dart';
import 'generated/schema_v2.dart' as v2;
import 'generated/schema_v3.dart' as v3;
void main() {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
late SchemaVerifier verifier;
setUpAll(() {
verifier = SchemaVerifier(GeneratedHelper());
});
group('simple database migrations', () {
// These simple tests verify all possible schema updates with a simple (no
// data) migration. This is a quick way to ensure that written database
// migrations properly alter the schema.
const versions = GeneratedHelper.versions;
for (final (i, fromVersion) in versions.indexed) {
group('from $fromVersion', () {
for (final toVersion in versions.skip(i + 1)) {
test('to $toVersion', () async {
final schema = await verifier.schemaAt(fromVersion);
final db = TabDatabase(schema.newConnection());
await verifier.migrateAndValidate(db, toVersion);
await db.close();
});
}
});
}
});
// The following template shows how to write tests ensuring your migrations
// preserve existing data.
// Testing this can be useful for migrations that change existing columns
// (e.g. by alterating their type or constraints). Migrations that only add
// tables or columns typically don't need these advanced tests. For more
// information, see https://drift.simonbinder.eu/migrations/tests/#verifying-data-integrity
// TODO: This generated template shows how these tests could be written. Adopt
// it to your own needs when testing migrations with data integrity.
test('migration from v2 to v3 does not corrupt data', () async {
// Add data to insert into the old database, and the expected rows after the
// migration.
// TODO: Fill these lists
final oldContainerData = <v2.ContainerData>[];
final expectedNewContainerData = <v3.ContainerData>[];
final oldTabData = <v2.TabData>[];
final expectedNewTabData = <v3.TabData>[];
final oldTabFtsData = <v2.TabFtsData>[];
final expectedNewTabFtsData = <v3.TabFtsData>[];
await verifier.testWithDataIntegrity(
oldVersion: 2,
newVersion: 3,
createOld: v2.DatabaseAtV2.new,
createNew: v3.DatabaseAtV3.new,
openTestedDatabase: TabDatabase.new,
createItems: (batch, oldDb) {
batch.insertAll(oldDb.container, oldContainerData);
batch.insertAll(oldDb.tab, oldTabData);
batch.insertAll(oldDb.tabFts, oldTabFtsData);
},
validateItems: (newDb) async {
expect(
expectedNewContainerData,
await newDb.select(newDb.container).get(),
);
expect(expectedNewTabData, await newDb.select(newDb.tab).get());
expect(expectedNewTabFtsData, await newDb.select(newDb.tabFts).get());
},
);
});
}
@@ -0,0 +1,181 @@
{
"_meta": {
"description": "This file contains a serialized version of schema entities for drift.",
"version": "1.3.0"
},
"options": {
"store_date_time_values_as_text": false
},
"entities": [
{
"id": 0,
"references": [],
"type": "table",
"data": {
"name": "top_site",
"was_declared_in_moor": true,
"columns": [
{
"name": "id",
"getter_name": "id",
"moor_type": "string",
"nullable": false,
"customConstraints": "PRIMARY KEY NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "title",
"getter_name": "title",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "url",
"getter_name": "url",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [],
"type_converter": {
"dart_expr": "const UriConverter()",
"dart_type_name": "Uri"
}
},
{
"name": "source",
"getter_name": "source",
"moor_type": "int",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [],
"type_converter": {
"dart_expr": "const EnumIndexConverter<StoredTopSiteSource>(StoredTopSiteSource.values)",
"dart_type_name": "StoredTopSiteSource"
}
},
{
"name": "order_key",
"getter_name": "orderKey",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "created_at",
"getter_name": "createdAt",
"moor_type": "dateTime",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": [
"UNIQUE(url)"
],
"unique_keys": [
[
"url"
]
]
}
},
{
"id": 1,
"references": [
0
],
"type": "index",
"data": {
"on": 0,
"name": "idx_top_site_order_key",
"sql": "CREATE INDEX idx_top_site_order_key ON top_site(order_key);",
"unique": false,
"columns": []
}
},
{
"id": 2,
"references": [],
"type": "table",
"data": {
"name": "top_site_seed_state",
"was_declared_in_moor": true,
"columns": [
{
"name": "seed_id",
"getter_name": "seedId",
"moor_type": "string",
"nullable": false,
"customConstraints": "PRIMARY KEY NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "applied_at",
"getter_name": "appliedAt",
"moor_type": "dateTime",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": []
}
}
],
"fixed_sql": [
{
"name": "top_site",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"top_site\" (\"id\" TEXT PRIMARY KEY NOT NULL, \"title\" TEXT NOT NULL, \"url\" TEXT NOT NULL, \"source\" INTEGER NOT NULL, \"order_key\" TEXT NOT NULL, \"created_at\" INTEGER NOT NULL, UNIQUE(url));"
}
]
},
{
"name": "idx_top_site_order_key",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE INDEX idx_top_site_order_key ON top_site (order_key)"
}
]
},
{
"name": "top_site_seed_state",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"top_site_seed_state\" (\"seed_id\" TEXT PRIMARY KEY NOT NULL, \"applied_at\" INTEGER NOT NULL);"
}
]
}
]
}
@@ -0,0 +1,21 @@
// dart format width=80
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
import 'package:drift/internal/migrations.dart';
import 'schema_v1.dart' as v1;
class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 1:
return v1.DatabaseAtV1(db);
default:
throw MissingSchemaException(version, versions);
}
}
static const versions = const [1];
}
@@ -0,0 +1,159 @@
// dart format width=80
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
class TopSite extends Table with TableInfo {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
TopSite(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> id = GeneratedColumn<String>(
'id',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<String> title = GeneratedColumn<String>(
'title',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<String> url = GeneratedColumn<String>(
'url',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<int> source = GeneratedColumn<int>(
'source',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<String> orderKey = GeneratedColumn<String>(
'order_key',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<int> createdAt = GeneratedColumn<int>(
'created_at',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [
id,
title,
url,
source,
orderKey,
createdAt,
];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'top_site';
@override
Set<GeneratedColumn> get $primaryKey => {id};
@override
List<Set<GeneratedColumn>> get uniqueKeys => [
{url},
];
@override
Never map(Map<String, dynamic> data, {String? tablePrefix}) {
throw UnsupportedError('TableInfo.map in schema verification code');
}
@override
TopSite createAlias(String alias) {
return TopSite(attachedDatabase, alias);
}
@override
List<String> get customConstraints => const ['UNIQUE(url)'];
@override
bool get dontWriteConstraints => true;
}
class TopSiteSeedState extends Table with TableInfo {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
TopSiteSeedState(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> seedId = GeneratedColumn<String>(
'seed_id',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<int> appliedAt = GeneratedColumn<int>(
'applied_at',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [seedId, appliedAt];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'top_site_seed_state';
@override
Set<GeneratedColumn> get $primaryKey => {seedId};
@override
Never map(Map<String, dynamic> data, {String? tablePrefix}) {
throw UnsupportedError('TableInfo.map in schema verification code');
}
@override
TopSiteSeedState createAlias(String alias) {
return TopSiteSeedState(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => true;
}
class DatabaseAtV1 extends GeneratedDatabase {
DatabaseAtV1(QueryExecutor e) : super(e);
late final TopSite topSite = TopSite(this);
late final Index idxTopSiteOrderKey = Index(
'idx_top_site_order_key',
'CREATE INDEX idx_top_site_order_key ON top_site (order_key)',
);
late final TopSiteSeedState topSiteSeedState = TopSiteSeedState(this);
@override
Iterable<TableInfo<Table, Object?>> get allTables =>
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities => [
topSite,
idxTopSiteOrderKey,
topSiteSeedState,
];
@override
int get schemaVersion => 1;
}
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2024-2026 Fabian Freund.
*
* This file is part of WebLibre
* (see https://weblibre.eu).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// dart format width=80
// ignore_for_file: unused_local_variable, unused_import
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations_native.dart';
import 'package:weblibre/features/geckoview/features/top_sites/data/database/database.dart';
import 'package:flutter_test/flutter_test.dart';
import 'generated/schema.dart';
import 'generated/schema_v1.dart' as v1;
void main() {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
late SchemaVerifier verifier;
setUpAll(() {
verifier = SchemaVerifier(GeneratedHelper());
});
group('simple database migrations', () {
const versions = GeneratedHelper.versions;
for (final (i, fromVersion) in versions.indexed) {
group('from $fromVersion', () {
for (final toVersion in versions.skip(i + 1)) {
test('to $toVersion', () async {
final schema = await verifier.schemaAt(fromVersion);
final db = TopSiteDatabase(schema.newConnection());
await verifier.migrateAndValidate(db, toVersion);
await db.close();
});
}
});
}
});
test('v1 schema creation works', () async {
final schema = await verifier.schemaAt(1);
final db = TopSiteDatabase(schema.newConnection());
await verifier.migrateAndValidate(db, 1);
await db.close();
});
}
@@ -0,0 +1,298 @@
{
"_meta": {
"description": "This file contains a serialized version of schema entities for drift.",
"version": "1.3.0"
},
"options": {
"store_date_time_values_as_text": false
},
"entities": [
{
"id": 0,
"references": [],
"type": "table",
"data": {
"name": "setting",
"was_declared_in_moor": true,
"columns": [
{
"name": "key",
"getter_name": "key",
"moor_type": "string",
"nullable": false,
"customConstraints": "PRIMARY KEY NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "partition_key",
"getter_name": "partitionKey",
"moor_type": "string",
"nullable": true,
"customConstraints": "",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "value",
"getter_name": "value",
"moor_type": "any",
"nullable": true,
"customConstraints": "",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": [],
"strict": true
}
},
{
"id": 1,
"references": [],
"type": "table",
"data": {
"name": "icon_cache",
"was_declared_in_moor": true,
"columns": [
{
"name": "origin",
"getter_name": "origin",
"moor_type": "string",
"nullable": false,
"customConstraints": "PRIMARY KEY NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "icon_data",
"getter_name": "iconData",
"moor_type": "blob",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "fetch_date",
"getter_name": "fetchDate",
"moor_type": "dateTime",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": []
}
},
{
"id": 2,
"references": [],
"type": "table",
"data": {
"name": "onboarding",
"was_declared_in_moor": true,
"columns": [
{
"name": "revision",
"getter_name": "revision",
"moor_type": "int",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "completion_date",
"getter_name": "completionDate",
"moor_type": "dateTime",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": []
}
},
{
"id": 3,
"references": [],
"type": "table",
"data": {
"name": "riverpod",
"was_declared_in_moor": true,
"columns": [
{
"name": "key",
"getter_name": "key",
"moor_type": "string",
"nullable": false,
"customConstraints": "PRIMARY KEY NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "json",
"getter_name": "json",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "expireAt",
"getter_name": "expireAt",
"moor_type": "dateTime",
"nullable": true,
"customConstraints": "",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "destroyKey",
"getter_name": "destroyKey",
"moor_type": "string",
"nullable": true,
"customConstraints": "",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": true,
"constraints": []
}
},
{
"id": 4,
"references": [],
"type": "table",
"data": {
"name": "toolbar_button_configs",
"was_declared_in_moor": true,
"columns": [
{
"name": "button_id",
"getter_name": "buttonId",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL PRIMARY KEY",
"default_dart": null,
"default_client_dart": null,
"dsl_features": [
"primary-key"
]
},
{
"name": "order_key",
"getter_name": "orderKey",
"moor_type": "string",
"nullable": false,
"customConstraints": "NOT NULL",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
},
{
"name": "is_visible",
"getter_name": "isVisible",
"moor_type": "int",
"nullable": false,
"customConstraints": "NOT NULL DEFAULT 1",
"default_dart": "const CustomExpression('1')",
"default_client_dart": null,
"dsl_features": []
},
{
"name": "fallback_id",
"getter_name": "fallbackId",
"moor_type": "string",
"nullable": true,
"customConstraints": "",
"default_dart": null,
"default_client_dart": null,
"dsl_features": []
}
],
"is_virtual": false,
"without_rowid": false,
"constraints": [],
"strict": true
}
}
],
"fixed_sql": [
{
"name": "setting",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"setting\" (\"key\" TEXT PRIMARY KEY NOT NULL, \"partition_key\" TEXT, \"value\" ANY) STRICT;"
}
]
},
{
"name": "icon_cache",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"icon_cache\" (\"origin\" TEXT PRIMARY KEY NOT NULL, \"icon_data\" BLOB NOT NULL, \"fetch_date\" INTEGER NOT NULL);"
}
]
},
{
"name": "onboarding",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"onboarding\" (\"revision\" INTEGER NOT NULL, \"completion_date\" INTEGER NOT NULL);"
}
]
},
{
"name": "riverpod",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"riverpod\" (\"key\" TEXT PRIMARY KEY NOT NULL, \"json\" TEXT NOT NULL, \"expireAt\" INTEGER, \"destroyKey\" TEXT) WITHOUT ROWID;"
}
]
},
{
"name": "toolbar_button_configs",
"sql": [
{
"dialect": "sqlite",
"sql": "CREATE TABLE IF NOT EXISTS \"toolbar_button_configs\" (\"button_id\" TEXT NOT NULL PRIMARY KEY, \"order_key\" TEXT NOT NULL, \"is_visible\" INTEGER NOT NULL DEFAULT 1, \"fallback_id\" TEXT) STRICT;"
}
]
}
]
}
@@ -0,0 +1,27 @@
// dart format width=80
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
import 'package:drift/internal/migrations.dart';
import 'schema_v1.dart' as v1;
import 'schema_v2.dart' as v2;
import 'schema_v3.dart' as v3;
class GeneratedHelper implements SchemaInstantiationHelper {
@override
GeneratedDatabase databaseForVersion(QueryExecutor db, int version) {
switch (version) {
case 1:
return v1.DatabaseAtV1(db);
case 2:
return v2.DatabaseAtV2(db);
case 3:
return v3.DatabaseAtV3(db);
default:
throw MissingSchemaException(version, versions);
}
}
static const versions = const [1, 2, 3];
}
@@ -0,0 +1,652 @@
// dart format width=80
import 'dart:typed_data' as i2;
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
class Setting extends Table with TableInfo<Setting, SettingData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Setting(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> key = GeneratedColumn<String>(
'key',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<String> partitionKey = GeneratedColumn<String>(
'partition_key',
aliasedName,
true,
type: DriftSqlType.string,
requiredDuringInsert: false,
$customConstraints: '',
);
late final GeneratedColumn<DriftAny> value = GeneratedColumn<DriftAny>(
'value',
aliasedName,
true,
type: DriftSqlType.any,
requiredDuringInsert: false,
$customConstraints: '',
);
@override
List<GeneratedColumn> get $columns => [key, partitionKey, value];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'setting';
@override
Set<GeneratedColumn> get $primaryKey => {key};
@override
SettingData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return SettingData(
key: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}key'],
)!,
partitionKey: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}partition_key'],
),
value: attachedDatabase.typeMapping.read(
DriftSqlType.any,
data['${effectivePrefix}value'],
),
);
}
@override
Setting createAlias(String alias) {
return Setting(attachedDatabase, alias);
}
@override
bool get isStrict => true;
@override
bool get dontWriteConstraints => true;
}
class SettingData extends DataClass implements Insertable<SettingData> {
final String key;
final String? partitionKey;
final DriftAny? value;
const SettingData({required this.key, this.partitionKey, this.value});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['key'] = Variable<String>(key);
if (!nullToAbsent || partitionKey != null) {
map['partition_key'] = Variable<String>(partitionKey);
}
if (!nullToAbsent || value != null) {
map['value'] = Variable<DriftAny>(value);
}
return map;
}
factory SettingData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return SettingData(
key: serializer.fromJson<String>(json['key']),
partitionKey: serializer.fromJson<String?>(json['partitionKey']),
value: serializer.fromJson<DriftAny?>(json['value']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'key': serializer.toJson<String>(key),
'partitionKey': serializer.toJson<String?>(partitionKey),
'value': serializer.toJson<DriftAny?>(value),
};
}
SettingData copyWith({
String? key,
Value<String?> partitionKey = const Value.absent(),
Value<DriftAny?> value = const Value.absent(),
}) => SettingData(
key: key ?? this.key,
partitionKey: partitionKey.present ? partitionKey.value : this.partitionKey,
value: value.present ? value.value : this.value,
);
SettingData copyWithCompanion(SettingCompanion data) {
return SettingData(
key: data.key.present ? data.key.value : this.key,
partitionKey: data.partitionKey.present
? data.partitionKey.value
: this.partitionKey,
value: data.value.present ? data.value.value : this.value,
);
}
@override
String toString() {
return (StringBuffer('SettingData(')
..write('key: $key, ')
..write('partitionKey: $partitionKey, ')
..write('value: $value')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(key, partitionKey, value);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is SettingData &&
other.key == this.key &&
other.partitionKey == this.partitionKey &&
other.value == this.value);
}
class SettingCompanion extends UpdateCompanion<SettingData> {
final Value<String> key;
final Value<String?> partitionKey;
final Value<DriftAny?> value;
final Value<int> rowid;
const SettingCompanion({
this.key = const Value.absent(),
this.partitionKey = const Value.absent(),
this.value = const Value.absent(),
this.rowid = const Value.absent(),
});
SettingCompanion.insert({
required String key,
this.partitionKey = const Value.absent(),
this.value = const Value.absent(),
this.rowid = const Value.absent(),
}) : key = Value(key);
static Insertable<SettingData> custom({
Expression<String>? key,
Expression<String>? partitionKey,
Expression<DriftAny>? value,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (key != null) 'key': key,
if (partitionKey != null) 'partition_key': partitionKey,
if (value != null) 'value': value,
if (rowid != null) 'rowid': rowid,
});
}
SettingCompanion copyWith({
Value<String>? key,
Value<String?>? partitionKey,
Value<DriftAny?>? value,
Value<int>? rowid,
}) {
return SettingCompanion(
key: key ?? this.key,
partitionKey: partitionKey ?? this.partitionKey,
value: value ?? this.value,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (key.present) {
map['key'] = Variable<String>(key.value);
}
if (partitionKey.present) {
map['partition_key'] = Variable<String>(partitionKey.value);
}
if (value.present) {
map['value'] = Variable<DriftAny>(value.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('SettingCompanion(')
..write('key: $key, ')
..write('partitionKey: $partitionKey, ')
..write('value: $value, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class IconCache extends Table with TableInfo<IconCache, IconCacheData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
IconCache(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> origin = GeneratedColumn<String>(
'origin',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<i2.Uint8List> iconData =
GeneratedColumn<i2.Uint8List>(
'icon_data',
aliasedName,
false,
type: DriftSqlType.blob,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<DateTime> fetchDate = GeneratedColumn<DateTime>(
'fetch_date',
aliasedName,
false,
type: DriftSqlType.dateTime,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [origin, iconData, fetchDate];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'icon_cache';
@override
Set<GeneratedColumn> get $primaryKey => {origin};
@override
IconCacheData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return IconCacheData(
origin: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}origin'],
)!,
iconData: attachedDatabase.typeMapping.read(
DriftSqlType.blob,
data['${effectivePrefix}icon_data'],
)!,
fetchDate: attachedDatabase.typeMapping.read(
DriftSqlType.dateTime,
data['${effectivePrefix}fetch_date'],
)!,
);
}
@override
IconCache createAlias(String alias) {
return IconCache(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => true;
}
class IconCacheData extends DataClass implements Insertable<IconCacheData> {
final String origin;
final i2.Uint8List iconData;
final DateTime fetchDate;
const IconCacheData({
required this.origin,
required this.iconData,
required this.fetchDate,
});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['origin'] = Variable<String>(origin);
map['icon_data'] = Variable<i2.Uint8List>(iconData);
map['fetch_date'] = Variable<DateTime>(fetchDate);
return map;
}
factory IconCacheData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return IconCacheData(
origin: serializer.fromJson<String>(json['origin']),
iconData: serializer.fromJson<i2.Uint8List>(json['iconData']),
fetchDate: serializer.fromJson<DateTime>(json['fetchDate']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'origin': serializer.toJson<String>(origin),
'iconData': serializer.toJson<i2.Uint8List>(iconData),
'fetchDate': serializer.toJson<DateTime>(fetchDate),
};
}
IconCacheData copyWith({
String? origin,
i2.Uint8List? iconData,
DateTime? fetchDate,
}) => IconCacheData(
origin: origin ?? this.origin,
iconData: iconData ?? this.iconData,
fetchDate: fetchDate ?? this.fetchDate,
);
IconCacheData copyWithCompanion(IconCacheCompanion data) {
return IconCacheData(
origin: data.origin.present ? data.origin.value : this.origin,
iconData: data.iconData.present ? data.iconData.value : this.iconData,
fetchDate: data.fetchDate.present ? data.fetchDate.value : this.fetchDate,
);
}
@override
String toString() {
return (StringBuffer('IconCacheData(')
..write('origin: $origin, ')
..write('iconData: $iconData, ')
..write('fetchDate: $fetchDate')
..write(')'))
.toString();
}
@override
int get hashCode =>
Object.hash(origin, $driftBlobEquality.hash(iconData), fetchDate);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is IconCacheData &&
other.origin == this.origin &&
$driftBlobEquality.equals(other.iconData, this.iconData) &&
other.fetchDate == this.fetchDate);
}
class IconCacheCompanion extends UpdateCompanion<IconCacheData> {
final Value<String> origin;
final Value<i2.Uint8List> iconData;
final Value<DateTime> fetchDate;
final Value<int> rowid;
const IconCacheCompanion({
this.origin = const Value.absent(),
this.iconData = const Value.absent(),
this.fetchDate = const Value.absent(),
this.rowid = const Value.absent(),
});
IconCacheCompanion.insert({
required String origin,
required i2.Uint8List iconData,
required DateTime fetchDate,
this.rowid = const Value.absent(),
}) : origin = Value(origin),
iconData = Value(iconData),
fetchDate = Value(fetchDate);
static Insertable<IconCacheData> custom({
Expression<String>? origin,
Expression<i2.Uint8List>? iconData,
Expression<DateTime>? fetchDate,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (origin != null) 'origin': origin,
if (iconData != null) 'icon_data': iconData,
if (fetchDate != null) 'fetch_date': fetchDate,
if (rowid != null) 'rowid': rowid,
});
}
IconCacheCompanion copyWith({
Value<String>? origin,
Value<i2.Uint8List>? iconData,
Value<DateTime>? fetchDate,
Value<int>? rowid,
}) {
return IconCacheCompanion(
origin: origin ?? this.origin,
iconData: iconData ?? this.iconData,
fetchDate: fetchDate ?? this.fetchDate,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (origin.present) {
map['origin'] = Variable<String>(origin.value);
}
if (iconData.present) {
map['icon_data'] = Variable<i2.Uint8List>(iconData.value);
}
if (fetchDate.present) {
map['fetch_date'] = Variable<DateTime>(fetchDate.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('IconCacheCompanion(')
..write('origin: $origin, ')
..write('iconData: $iconData, ')
..write('fetchDate: $fetchDate, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class Onboarding extends Table with TableInfo<Onboarding, OnboardingData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Onboarding(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> revision = GeneratedColumn<int>(
'revision',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<DateTime> completionDate =
GeneratedColumn<DateTime>(
'completion_date',
aliasedName,
false,
type: DriftSqlType.dateTime,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [revision, completionDate];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'onboarding';
@override
Set<GeneratedColumn> get $primaryKey => const {};
@override
OnboardingData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return OnboardingData(
revision: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}revision'],
)!,
completionDate: attachedDatabase.typeMapping.read(
DriftSqlType.dateTime,
data['${effectivePrefix}completion_date'],
)!,
);
}
@override
Onboarding createAlias(String alias) {
return Onboarding(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => true;
}
class OnboardingData extends DataClass implements Insertable<OnboardingData> {
final int revision;
final DateTime completionDate;
const OnboardingData({required this.revision, required this.completionDate});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['revision'] = Variable<int>(revision);
map['completion_date'] = Variable<DateTime>(completionDate);
return map;
}
factory OnboardingData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return OnboardingData(
revision: serializer.fromJson<int>(json['revision']),
completionDate: serializer.fromJson<DateTime>(json['completionDate']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'revision': serializer.toJson<int>(revision),
'completionDate': serializer.toJson<DateTime>(completionDate),
};
}
OnboardingData copyWith({int? revision, DateTime? completionDate}) =>
OnboardingData(
revision: revision ?? this.revision,
completionDate: completionDate ?? this.completionDate,
);
OnboardingData copyWithCompanion(OnboardingCompanion data) {
return OnboardingData(
revision: data.revision.present ? data.revision.value : this.revision,
completionDate: data.completionDate.present
? data.completionDate.value
: this.completionDate,
);
}
@override
String toString() {
return (StringBuffer('OnboardingData(')
..write('revision: $revision, ')
..write('completionDate: $completionDate')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(revision, completionDate);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is OnboardingData &&
other.revision == this.revision &&
other.completionDate == this.completionDate);
}
class OnboardingCompanion extends UpdateCompanion<OnboardingData> {
final Value<int> revision;
final Value<DateTime> completionDate;
final Value<int> rowid;
const OnboardingCompanion({
this.revision = const Value.absent(),
this.completionDate = const Value.absent(),
this.rowid = const Value.absent(),
});
OnboardingCompanion.insert({
required int revision,
required DateTime completionDate,
this.rowid = const Value.absent(),
}) : revision = Value(revision),
completionDate = Value(completionDate);
static Insertable<OnboardingData> custom({
Expression<int>? revision,
Expression<DateTime>? completionDate,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (revision != null) 'revision': revision,
if (completionDate != null) 'completion_date': completionDate,
if (rowid != null) 'rowid': rowid,
});
}
OnboardingCompanion copyWith({
Value<int>? revision,
Value<DateTime>? completionDate,
Value<int>? rowid,
}) {
return OnboardingCompanion(
revision: revision ?? this.revision,
completionDate: completionDate ?? this.completionDate,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (revision.present) {
map['revision'] = Variable<int>(revision.value);
}
if (completionDate.present) {
map['completion_date'] = Variable<DateTime>(completionDate.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('OnboardingCompanion(')
..write('revision: $revision, ')
..write('completionDate: $completionDate, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class DatabaseAtV1 extends GeneratedDatabase {
DatabaseAtV1(QueryExecutor e) : super(e);
late final Setting setting = Setting(this);
late final IconCache iconCache = IconCache(this);
late final Onboarding onboarding = Onboarding(this);
@override
Iterable<TableInfo<Table, Object?>> get allTables =>
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities => [
setting,
iconCache,
onboarding,
];
@override
int get schemaVersion => 1;
}
@@ -0,0 +1,902 @@
// dart format width=80
import 'dart:typed_data' as i2;
// GENERATED BY drift_dev, DO NOT MODIFY.
// ignore_for_file: type=lint,unused_import
//
import 'package:drift/drift.dart';
class Setting extends Table with TableInfo<Setting, SettingData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Setting(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> key = GeneratedColumn<String>(
'key',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<String> partitionKey = GeneratedColumn<String>(
'partition_key',
aliasedName,
true,
type: DriftSqlType.string,
requiredDuringInsert: false,
$customConstraints: '',
);
late final GeneratedColumn<DriftAny> value = GeneratedColumn<DriftAny>(
'value',
aliasedName,
true,
type: DriftSqlType.any,
requiredDuringInsert: false,
$customConstraints: '',
);
@override
List<GeneratedColumn> get $columns => [key, partitionKey, value];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'setting';
@override
Set<GeneratedColumn> get $primaryKey => {key};
@override
SettingData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return SettingData(
key: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}key'],
)!,
partitionKey: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}partition_key'],
),
value: attachedDatabase.typeMapping.read(
DriftSqlType.any,
data['${effectivePrefix}value'],
),
);
}
@override
Setting createAlias(String alias) {
return Setting(attachedDatabase, alias);
}
@override
bool get isStrict => true;
@override
bool get dontWriteConstraints => true;
}
class SettingData extends DataClass implements Insertable<SettingData> {
final String key;
final String? partitionKey;
final DriftAny? value;
const SettingData({required this.key, this.partitionKey, this.value});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['key'] = Variable<String>(key);
if (!nullToAbsent || partitionKey != null) {
map['partition_key'] = Variable<String>(partitionKey);
}
if (!nullToAbsent || value != null) {
map['value'] = Variable<DriftAny>(value);
}
return map;
}
factory SettingData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return SettingData(
key: serializer.fromJson<String>(json['key']),
partitionKey: serializer.fromJson<String?>(json['partitionKey']),
value: serializer.fromJson<DriftAny?>(json['value']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'key': serializer.toJson<String>(key),
'partitionKey': serializer.toJson<String?>(partitionKey),
'value': serializer.toJson<DriftAny?>(value),
};
}
SettingData copyWith({
String? key,
Value<String?> partitionKey = const Value.absent(),
Value<DriftAny?> value = const Value.absent(),
}) => SettingData(
key: key ?? this.key,
partitionKey: partitionKey.present ? partitionKey.value : this.partitionKey,
value: value.present ? value.value : this.value,
);
SettingData copyWithCompanion(SettingCompanion data) {
return SettingData(
key: data.key.present ? data.key.value : this.key,
partitionKey: data.partitionKey.present
? data.partitionKey.value
: this.partitionKey,
value: data.value.present ? data.value.value : this.value,
);
}
@override
String toString() {
return (StringBuffer('SettingData(')
..write('key: $key, ')
..write('partitionKey: $partitionKey, ')
..write('value: $value')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(key, partitionKey, value);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is SettingData &&
other.key == this.key &&
other.partitionKey == this.partitionKey &&
other.value == this.value);
}
class SettingCompanion extends UpdateCompanion<SettingData> {
final Value<String> key;
final Value<String?> partitionKey;
final Value<DriftAny?> value;
final Value<int> rowid;
const SettingCompanion({
this.key = const Value.absent(),
this.partitionKey = const Value.absent(),
this.value = const Value.absent(),
this.rowid = const Value.absent(),
});
SettingCompanion.insert({
required String key,
this.partitionKey = const Value.absent(),
this.value = const Value.absent(),
this.rowid = const Value.absent(),
}) : key = Value(key);
static Insertable<SettingData> custom({
Expression<String>? key,
Expression<String>? partitionKey,
Expression<DriftAny>? value,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (key != null) 'key': key,
if (partitionKey != null) 'partition_key': partitionKey,
if (value != null) 'value': value,
if (rowid != null) 'rowid': rowid,
});
}
SettingCompanion copyWith({
Value<String>? key,
Value<String?>? partitionKey,
Value<DriftAny?>? value,
Value<int>? rowid,
}) {
return SettingCompanion(
key: key ?? this.key,
partitionKey: partitionKey ?? this.partitionKey,
value: value ?? this.value,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (key.present) {
map['key'] = Variable<String>(key.value);
}
if (partitionKey.present) {
map['partition_key'] = Variable<String>(partitionKey.value);
}
if (value.present) {
map['value'] = Variable<DriftAny>(value.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('SettingCompanion(')
..write('key: $key, ')
..write('partitionKey: $partitionKey, ')
..write('value: $value, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class IconCache extends Table with TableInfo<IconCache, IconCacheData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
IconCache(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> origin = GeneratedColumn<String>(
'origin',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<i2.Uint8List> iconData =
GeneratedColumn<i2.Uint8List>(
'icon_data',
aliasedName,
false,
type: DriftSqlType.blob,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<int> fetchDate = GeneratedColumn<int>(
'fetch_date',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [origin, iconData, fetchDate];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'icon_cache';
@override
Set<GeneratedColumn> get $primaryKey => {origin};
@override
IconCacheData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return IconCacheData(
origin: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}origin'],
)!,
iconData: attachedDatabase.typeMapping.read(
DriftSqlType.blob,
data['${effectivePrefix}icon_data'],
)!,
fetchDate: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}fetch_date'],
)!,
);
}
@override
IconCache createAlias(String alias) {
return IconCache(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => true;
}
class IconCacheData extends DataClass implements Insertable<IconCacheData> {
final String origin;
final i2.Uint8List iconData;
final int fetchDate;
const IconCacheData({
required this.origin,
required this.iconData,
required this.fetchDate,
});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['origin'] = Variable<String>(origin);
map['icon_data'] = Variable<i2.Uint8List>(iconData);
map['fetch_date'] = Variable<int>(fetchDate);
return map;
}
factory IconCacheData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return IconCacheData(
origin: serializer.fromJson<String>(json['origin']),
iconData: serializer.fromJson<i2.Uint8List>(json['iconData']),
fetchDate: serializer.fromJson<int>(json['fetchDate']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'origin': serializer.toJson<String>(origin),
'iconData': serializer.toJson<i2.Uint8List>(iconData),
'fetchDate': serializer.toJson<int>(fetchDate),
};
}
IconCacheData copyWith({
String? origin,
i2.Uint8List? iconData,
int? fetchDate,
}) => IconCacheData(
origin: origin ?? this.origin,
iconData: iconData ?? this.iconData,
fetchDate: fetchDate ?? this.fetchDate,
);
IconCacheData copyWithCompanion(IconCacheCompanion data) {
return IconCacheData(
origin: data.origin.present ? data.origin.value : this.origin,
iconData: data.iconData.present ? data.iconData.value : this.iconData,
fetchDate: data.fetchDate.present ? data.fetchDate.value : this.fetchDate,
);
}
@override
String toString() {
return (StringBuffer('IconCacheData(')
..write('origin: $origin, ')
..write('iconData: $iconData, ')
..write('fetchDate: $fetchDate')
..write(')'))
.toString();
}
@override
int get hashCode =>
Object.hash(origin, $driftBlobEquality.hash(iconData), fetchDate);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is IconCacheData &&
other.origin == this.origin &&
$driftBlobEquality.equals(other.iconData, this.iconData) &&
other.fetchDate == this.fetchDate);
}
class IconCacheCompanion extends UpdateCompanion<IconCacheData> {
final Value<String> origin;
final Value<i2.Uint8List> iconData;
final Value<int> fetchDate;
final Value<int> rowid;
const IconCacheCompanion({
this.origin = const Value.absent(),
this.iconData = const Value.absent(),
this.fetchDate = const Value.absent(),
this.rowid = const Value.absent(),
});
IconCacheCompanion.insert({
required String origin,
required i2.Uint8List iconData,
required int fetchDate,
this.rowid = const Value.absent(),
}) : origin = Value(origin),
iconData = Value(iconData),
fetchDate = Value(fetchDate);
static Insertable<IconCacheData> custom({
Expression<String>? origin,
Expression<i2.Uint8List>? iconData,
Expression<int>? fetchDate,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (origin != null) 'origin': origin,
if (iconData != null) 'icon_data': iconData,
if (fetchDate != null) 'fetch_date': fetchDate,
if (rowid != null) 'rowid': rowid,
});
}
IconCacheCompanion copyWith({
Value<String>? origin,
Value<i2.Uint8List>? iconData,
Value<int>? fetchDate,
Value<int>? rowid,
}) {
return IconCacheCompanion(
origin: origin ?? this.origin,
iconData: iconData ?? this.iconData,
fetchDate: fetchDate ?? this.fetchDate,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (origin.present) {
map['origin'] = Variable<String>(origin.value);
}
if (iconData.present) {
map['icon_data'] = Variable<i2.Uint8List>(iconData.value);
}
if (fetchDate.present) {
map['fetch_date'] = Variable<int>(fetchDate.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('IconCacheCompanion(')
..write('origin: $origin, ')
..write('iconData: $iconData, ')
..write('fetchDate: $fetchDate, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class Onboarding extends Table with TableInfo<Onboarding, OnboardingData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Onboarding(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<int> revision = GeneratedColumn<int>(
'revision',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<int> completionDate = GeneratedColumn<int>(
'completion_date',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
@override
List<GeneratedColumn> get $columns => [revision, completionDate];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'onboarding';
@override
Set<GeneratedColumn> get $primaryKey => const {};
@override
OnboardingData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return OnboardingData(
revision: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}revision'],
)!,
completionDate: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}completion_date'],
)!,
);
}
@override
Onboarding createAlias(String alias) {
return Onboarding(attachedDatabase, alias);
}
@override
bool get dontWriteConstraints => true;
}
class OnboardingData extends DataClass implements Insertable<OnboardingData> {
final int revision;
final int completionDate;
const OnboardingData({required this.revision, required this.completionDate});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['revision'] = Variable<int>(revision);
map['completion_date'] = Variable<int>(completionDate);
return map;
}
factory OnboardingData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return OnboardingData(
revision: serializer.fromJson<int>(json['revision']),
completionDate: serializer.fromJson<int>(json['completionDate']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'revision': serializer.toJson<int>(revision),
'completionDate': serializer.toJson<int>(completionDate),
};
}
OnboardingData copyWith({int? revision, int? completionDate}) =>
OnboardingData(
revision: revision ?? this.revision,
completionDate: completionDate ?? this.completionDate,
);
OnboardingData copyWithCompanion(OnboardingCompanion data) {
return OnboardingData(
revision: data.revision.present ? data.revision.value : this.revision,
completionDate: data.completionDate.present
? data.completionDate.value
: this.completionDate,
);
}
@override
String toString() {
return (StringBuffer('OnboardingData(')
..write('revision: $revision, ')
..write('completionDate: $completionDate')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(revision, completionDate);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is OnboardingData &&
other.revision == this.revision &&
other.completionDate == this.completionDate);
}
class OnboardingCompanion extends UpdateCompanion<OnboardingData> {
final Value<int> revision;
final Value<int> completionDate;
final Value<int> rowid;
const OnboardingCompanion({
this.revision = const Value.absent(),
this.completionDate = const Value.absent(),
this.rowid = const Value.absent(),
});
OnboardingCompanion.insert({
required int revision,
required int completionDate,
this.rowid = const Value.absent(),
}) : revision = Value(revision),
completionDate = Value(completionDate);
static Insertable<OnboardingData> custom({
Expression<int>? revision,
Expression<int>? completionDate,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (revision != null) 'revision': revision,
if (completionDate != null) 'completion_date': completionDate,
if (rowid != null) 'rowid': rowid,
});
}
OnboardingCompanion copyWith({
Value<int>? revision,
Value<int>? completionDate,
Value<int>? rowid,
}) {
return OnboardingCompanion(
revision: revision ?? this.revision,
completionDate: completionDate ?? this.completionDate,
rowid: rowid ?? this.rowid,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (revision.present) {
map['revision'] = Variable<int>(revision.value);
}
if (completionDate.present) {
map['completion_date'] = Variable<int>(completionDate.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('OnboardingCompanion(')
..write('revision: $revision, ')
..write('completionDate: $completionDate, ')
..write('rowid: $rowid')
..write(')'))
.toString();
}
}
class Riverpod extends Table with TableInfo<Riverpod, RiverpodData> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
Riverpod(this.attachedDatabase, [this._alias]);
late final GeneratedColumn<String> key = GeneratedColumn<String>(
'key',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'PRIMARY KEY NOT NULL',
);
late final GeneratedColumn<String> json = GeneratedColumn<String>(
'json',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
$customConstraints: 'NOT NULL',
);
late final GeneratedColumn<int> expireAt = GeneratedColumn<int>(
'expireAt',
aliasedName,
true,
type: DriftSqlType.int,
requiredDuringInsert: false,
$customConstraints: '',
);
late final GeneratedColumn<String> destroyKey = GeneratedColumn<String>(
'destroyKey',
aliasedName,
true,
type: DriftSqlType.string,
requiredDuringInsert: false,
$customConstraints: '',
);
@override
List<GeneratedColumn> get $columns => [key, json, expireAt, destroyKey];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'riverpod';
@override
Set<GeneratedColumn> get $primaryKey => {key};
@override
RiverpodData map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return RiverpodData(
key: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}key'],
)!,
json: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}json'],
)!,
expireAt: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}expireAt'],
),
destroyKey: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}destroyKey'],
),
);
}
@override
Riverpod createAlias(String alias) {
return Riverpod(attachedDatabase, alias);
}
@override
bool get withoutRowId => true;
@override
bool get dontWriteConstraints => true;
}
class RiverpodData extends DataClass implements Insertable<RiverpodData> {
final String key;
final String json;
final int? expireAt;
final String? destroyKey;
const RiverpodData({
required this.key,
required this.json,
this.expireAt,
this.destroyKey,
});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['key'] = Variable<String>(key);
map['json'] = Variable<String>(json);
if (!nullToAbsent || expireAt != null) {
map['expireAt'] = Variable<int>(expireAt);
}
if (!nullToAbsent || destroyKey != null) {
map['destroyKey'] = Variable<String>(destroyKey);
}
return map;
}
factory RiverpodData.fromJson(
Map<String, dynamic> json, {
ValueSerializer? serializer,
}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return RiverpodData(
key: serializer.fromJson<String>(json['key']),
json: serializer.fromJson<String>(json['json']),
expireAt: serializer.fromJson<int?>(json['expireAt']),
destroyKey: serializer.fromJson<String?>(json['destroyKey']),
);
}
@override
Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'key': serializer.toJson<String>(key),
'json': serializer.toJson<String>(json),
'expireAt': serializer.toJson<int?>(expireAt),
'destroyKey': serializer.toJson<String?>(destroyKey),
};
}
RiverpodData copyWith({
String? key,
String? json,
Value<int?> expireAt = const Value.absent(),
Value<String?> destroyKey = const Value.absent(),
}) => RiverpodData(
key: key ?? this.key,
json: json ?? this.json,
expireAt: expireAt.present ? expireAt.value : this.expireAt,
destroyKey: destroyKey.present ? destroyKey.value : this.destroyKey,
);
RiverpodData copyWithCompanion(RiverpodCompanion data) {
return RiverpodData(
key: data.key.present ? data.key.value : this.key,
json: data.json.present ? data.json.value : this.json,
expireAt: data.expireAt.present ? data.expireAt.value : this.expireAt,
destroyKey: data.destroyKey.present
? data.destroyKey.value
: this.destroyKey,
);
}
@override
String toString() {
return (StringBuffer('RiverpodData(')
..write('key: $key, ')
..write('json: $json, ')
..write('expireAt: $expireAt, ')
..write('destroyKey: $destroyKey')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(key, json, expireAt, destroyKey);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is RiverpodData &&
other.key == this.key &&
other.json == this.json &&
other.expireAt == this.expireAt &&
other.destroyKey == this.destroyKey);
}
class RiverpodCompanion extends UpdateCompanion<RiverpodData> {
final Value<String> key;
final Value<String> json;
final Value<int?> expireAt;
final Value<String?> destroyKey;
const RiverpodCompanion({
this.key = const Value.absent(),
this.json = const Value.absent(),
this.expireAt = const Value.absent(),
this.destroyKey = const Value.absent(),
});
RiverpodCompanion.insert({
required String key,
required String json,
this.expireAt = const Value.absent(),
this.destroyKey = const Value.absent(),
}) : key = Value(key),
json = Value(json);
static Insertable<RiverpodData> custom({
Expression<String>? key,
Expression<String>? json,
Expression<int>? expireAt,
Expression<String>? destroyKey,
}) {
return RawValuesInsertable({
if (key != null) 'key': key,
if (json != null) 'json': json,
if (expireAt != null) 'expireAt': expireAt,
if (destroyKey != null) 'destroyKey': destroyKey,
});
}
RiverpodCompanion copyWith({
Value<String>? key,
Value<String>? json,
Value<int?>? expireAt,
Value<String?>? destroyKey,
}) {
return RiverpodCompanion(
key: key ?? this.key,
json: json ?? this.json,
expireAt: expireAt ?? this.expireAt,
destroyKey: destroyKey ?? this.destroyKey,
);
}
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
if (key.present) {
map['key'] = Variable<String>(key.value);
}
if (json.present) {
map['json'] = Variable<String>(json.value);
}
if (expireAt.present) {
map['expireAt'] = Variable<int>(expireAt.value);
}
if (destroyKey.present) {
map['destroyKey'] = Variable<String>(destroyKey.value);
}
return map;
}
@override
String toString() {
return (StringBuffer('RiverpodCompanion(')
..write('key: $key, ')
..write('json: $json, ')
..write('expireAt: $expireAt, ')
..write('destroyKey: $destroyKey')
..write(')'))
.toString();
}
}
class DatabaseAtV2 extends GeneratedDatabase {
DatabaseAtV2(QueryExecutor e) : super(e);
late final Setting setting = Setting(this);
late final IconCache iconCache = IconCache(this);
late final Onboarding onboarding = Onboarding(this);
late final Riverpod riverpod = Riverpod(this);
@override
Iterable<TableInfo<Table, Object?>> get allTables =>
allSchemaEntities.whereType<TableInfo<Table, Object?>>();
@override
List<DatabaseSchemaEntity> get allSchemaEntities => [
setting,
iconCache,
onboarding,
riverpod,
];
@override
int get schemaVersion => 2;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,84 @@
// dart format width=80
// ignore_for_file: unused_local_variable, unused_import
import 'package:drift/drift.dart';
import 'package:drift_dev/api/migrations_native.dart';
import 'package:weblibre/features/user/data/database/database.dart';
import 'package:flutter_test/flutter_test.dart';
import 'generated/schema.dart';
import 'generated/schema_v1.dart' as v1;
import 'generated/schema_v2.dart' as v2;
void main() {
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
late SchemaVerifier verifier;
setUpAll(() {
verifier = SchemaVerifier(GeneratedHelper());
});
group('simple database migrations', () {
// These simple tests verify all possible schema updates with a simple (no
// data) migration. This is a quick way to ensure that written database
// migrations properly alter the schema.
const versions = GeneratedHelper.versions;
for (final (i, fromVersion) in versions.indexed) {
group('from $fromVersion', () {
for (final toVersion in versions.skip(i + 1)) {
test('to $toVersion', () async {
final schema = await verifier.schemaAt(fromVersion);
final db = UserDatabase(schema.newConnection());
await verifier.migrateAndValidate(db, toVersion);
await db.close();
});
}
});
}
});
// The following template shows how to write tests ensuring your migrations
// preserve existing data.
// Testing this can be useful for migrations that change existing columns
// (e.g. by alterating their type or constraints). Migrations that only add
// tables or columns typically don't need these advanced tests. For more
// information, see https://drift.simonbinder.eu/migrations/tests/#verifying-data-integrity
// TODO: This generated template shows how these tests could be written. Adopt
// it to your own needs when testing migrations with data integrity.
test('migration from v1 to v2 does not corrupt data', () async {
// Add data to insert into the old database, and the expected rows after the
// migration.
// TODO: Fill these lists
final oldSettingData = <v1.SettingData>[];
final expectedNewSettingData = <v2.SettingData>[];
final oldIconCacheData = <v1.IconCacheData>[];
final expectedNewIconCacheData = <v2.IconCacheData>[];
final oldOnboardingData = <v1.OnboardingData>[];
final expectedNewOnboardingData = <v2.OnboardingData>[];
await verifier.testWithDataIntegrity(
oldVersion: 1,
newVersion: 2,
createOld: v1.DatabaseAtV1.new,
createNew: v2.DatabaseAtV2.new,
openTestedDatabase: UserDatabase.new,
createItems: (batch, oldDb) {
batch.insertAll(oldDb.setting, oldSettingData);
batch.insertAll(oldDb.iconCache, oldIconCacheData);
batch.insertAll(oldDb.onboarding, oldOnboardingData);
},
validateItems: (newDb) async {
expect(expectedNewSettingData, await newDb.select(newDb.setting).get());
expect(
expectedNewIconCacheData,
await newDb.select(newDb.iconCache).get(),
);
expect(
expectedNewOnboardingData,
await newDb.select(newDb.onboarding).get(),
);
},
);
});
}
@@ -0,0 +1,69 @@
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:weblibre/data/database/functions/lexo_rank_functions.dart';
import 'package:weblibre/features/geckoview/features/browser/features/contextual_toolbar/data/providers/toolbar_button_configs.dart';
import 'package:weblibre/features/user/data/database/database.dart';
void main() {
late UserDatabase db;
setUp(() {
db = UserDatabase(
NativeDatabase.memory(
setup: (database) {
registerLexorankFunctions(database);
},
),
);
});
tearDown(() async {
await db.close();
});
group('ToolbarButtonConfigDao', () {
test(
'seedMissing inserts self-referential fallback rows in two phases',
() async {
await db.toolbarButtonConfigDao.seedMissing([
(
buttonId: 'back',
defaultVisible: true,
defaultFallback: 'bookmarks',
),
(buttonId: 'bookmarks', defaultVisible: false, defaultFallback: null),
(buttonId: 'forward', defaultVisible: true, defaultFallback: 'share'),
(buttonId: 'share', defaultVisible: false, defaultFallback: null),
]);
final configs = await db.toolbarButtonConfigDao.getAll();
final configsById = {
for (final config in configs) config.buttonId: config,
};
expect(configsById['back']?.fallbackId, 'bookmarks');
expect(configsById['forward']?.fallbackId, 'share');
},
);
test(
'replaceAll persists default toolbar fallbacks without FK failures',
() async {
await expectLater(
db.toolbarButtonConfigDao.replaceAll(
buildDefaultToolbarButtonConfigs(),
),
completes,
);
final configs = await db.toolbarButtonConfigDao.getAll();
final configsById = {
for (final config in configs) config.buttonId: config,
};
expect(configsById['back']?.fallbackId, 'bookmarks');
expect(configsById['forward']?.fallbackId, 'share');
},
);
});
}