Skip to content

Commit

Permalink
rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tshedor committed Sep 20, 2024
1 parent 1787ee6 commit a029e62
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 147 deletions.
49 changes: 49 additions & 0 deletions example_supabase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutterplugins
.flutterpluginsdependencies
.pubcache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
windows/*
web/*
macos/*
linux/*
android/*
ios/*
45 changes: 45 additions & 0 deletions example_supabase/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "2663184aa79047d0a33a14a3b607954f8fdd8730"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: android
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: ios
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: linux
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: macos
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: web
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: windows
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- "lib/main.dart"
- "ios/Runner.xcodeproj/project.pbxproj"
67 changes: 3 additions & 64 deletions example_supabase/lib/brick/adapters/customer_adapter.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,20 @@ Future<Customer> _$CustomerFromSupabase(Map<String, dynamic> data,
return Customer(
id: data['id'] as String,
firstName: data['first_name'] as String?,
lastName: data['last_name'] as String?,
pizzas: await Future.wait<Pizza>(data['pizzas']
?.map(
(d) => PizzaAdapter().fromSupabase(d, provider: provider, repository: repository))
.toList()
.cast<Future<Pizza>>() ??
[]));
lastName: data['last_name'] as String?);
}

Future<Map<String, dynamic>> _$CustomerToSupabase(Customer instance,
{required SupabaseProvider provider, OfflineFirstWithSupabaseRepository? repository}) async {
return {
'id': instance.id,
'first_name': instance.firstName,
'last_name': instance.lastName,
'pizzas': await Future.wait<Map<String, dynamic>>(instance.pizzas
.map((s) => PizzaAdapter().toSupabase(s, provider: provider, repository: repository))
.toList())
};
return {'id': instance.id, 'first_name': instance.firstName, 'last_name': instance.lastName};
}

Future<Customer> _$CustomerFromSqlite(Map<String, dynamic> data,
{required SqliteProvider provider, OfflineFirstWithSupabaseRepository? repository}) async {
return Customer(
id: data['id'] as String,
firstName: data['first_name'] == null ? null : data['first_name'] as String?,
lastName: data['last_name'] == null ? null : data['last_name'] as String?,
pizzas: (await provider.rawQuery(
'SELECT DISTINCT `f_Pizza_brick_id` FROM `_brick_Customer_pizzas` WHERE l_Customer_brick_id = ?',
[data['_brick_id'] as int]).then((results) {
final ids = results.map((r) => r['f_Pizza_brick_id']);
return Future.wait<Pizza>(ids.map((primaryKey) => repository!
.getAssociation<Pizza>(
Query.where('primaryKey', primaryKey, limit1: true),
)
.then((r) => r!.first)));
}))
.toList()
.cast<Pizza>())
lastName: data['last_name'] == null ? null : data['last_name'] as String?)
..primaryKey = data['_brick_id'] as int;
}

Expand Down Expand Up @@ -74,12 +49,6 @@ class CustomerAdapter extends OfflineFirstWithSupabaseAdapter<Customer> {
'lastName': const RuntimeSupabaseColumnDefinition(
association: false,
columnName: 'last_name',
),
'pizzas': const RuntimeSupabaseColumnDefinition(
association: true,
columnName: 'pizzas',
associationType: Pizza,
associationIsNullable: false,
)
};
@override
Expand Down Expand Up @@ -111,12 +80,6 @@ class CustomerAdapter extends OfflineFirstWithSupabaseAdapter<Customer> {
columnName: 'last_name',
iterable: false,
type: String,
),
'pizzas': const RuntimeSqliteColumnDefinition(
association: true,
columnName: 'pizzas',
iterable: true,
type: Pizza,
)
};
@override
Expand All @@ -134,30 +97,6 @@ class CustomerAdapter extends OfflineFirstWithSupabaseAdapter<Customer> {

@override
final String tableName = 'Customer';
@override
Future<void> afterSave(instance, {required provider, repository}) async {
if (instance.primaryKey != null) {
final pizzasOldColumns = await provider.rawQuery(
'SELECT `f_Pizza_brick_id` FROM `_brick_Customer_pizzas` WHERE `l_Customer_brick_id` = ?',
[instance.primaryKey]);
final pizzasOldIds = pizzasOldColumns.map((a) => a['f_Pizza_brick_id']);
final pizzasNewIds = instance.pizzas.map((s) => s.primaryKey).whereType<int>();
final pizzasIdsToDelete = pizzasOldIds.where((id) => !pizzasNewIds.contains(id));

await Future.wait<void>(pizzasIdsToDelete.map((id) async {
return await provider.rawExecute(
'DELETE FROM `_brick_Customer_pizzas` WHERE `l_Customer_brick_id` = ? AND `f_Pizza_brick_id` = ?',
[instance.primaryKey, id]).catchError((e) => null);
}));

await Future.wait<int?>(instance.pizzas.map((s) async {
final id = s.primaryKey ?? await provider.upsert<Pizza>(s, repository: repository);
return await provider.rawInsert(
'INSERT OR IGNORE INTO `_brick_Customer_pizzas` (`l_Customer_brick_id`, `f_Pizza_brick_id`) VALUES (?, ?)',
[instance.primaryKey, id]);
}));
}
}

@override
Future<Customer> fromSupabase(Map<String, dynamic> input,
Expand Down
27 changes: 24 additions & 3 deletions example_supabase/lib/brick/adapters/pizza_adapter.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ part of '../brick.g.dart';

Future<Pizza> _$PizzaFromSupabase(Map<String, dynamic> data,
{required SupabaseProvider provider, OfflineFirstWithSupabaseRepository? repository}) async {
return Pizza(id: data['id'] as String, frozen: data['frozen'] as bool);
return Pizza(
id: data['id'] as String,
frozen: data['frozen'] as bool,
customer: await CustomerAdapter()
.fromSupabase(data['customer'], provider: provider, repository: repository));
}

Future<Map<String, dynamic>> _$PizzaToSupabase(Pizza instance,
Expand All @@ -19,13 +23,24 @@ Future<Map<String, dynamic>> _$PizzaToSupabase(Pizza instance,

Future<Pizza> _$PizzaFromSqlite(Map<String, dynamic> data,
{required SqliteProvider provider, OfflineFirstWithSupabaseRepository? repository}) async {
return Pizza(id: data['id'] as String, frozen: data['frozen'] == 1)
return Pizza(
id: data['id'] as String,
frozen: data['frozen'] == 1,
customer: (await repository!.getAssociation<Customer>(
Query.where('primaryKey', data['customer_Customer_brick_id'] as int, limit1: true),
))!
.first)
..primaryKey = data['_brick_id'] as int;
}

Future<Map<String, dynamic>> _$PizzaToSqlite(Pizza instance,
{required SqliteProvider provider, OfflineFirstWithSupabaseRepository? repository}) async {
return {'id': instance.id, 'frozen': instance.frozen ? 1 : 0};
return {
'id': instance.id,
'frozen': instance.frozen ? 1 : 0,
'customer_Customer_brick_id': instance.customer.primaryKey ??
await provider.upsert<Customer>(instance.customer, repository: repository)
};
}

/// Construct a [Pizza]
Expand Down Expand Up @@ -81,6 +96,12 @@ class PizzaAdapter extends OfflineFirstWithSupabaseAdapter<Pizza> {
columnName: 'frozen',
iterable: false,
type: bool,
),
'customer': const RuntimeSqliteColumnDefinition(
association: true,
columnName: 'customer_Customer_brick_id',
iterable: false,
type: Customer,
)
};
@override
Expand Down
2 changes: 1 addition & 1 deletion example_supabase/lib/brick/brick.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:brick_sqlite/brick_sqlite.dart';
// ignore: unused_import, unused_shown_name, unnecessary_import
import 'package:brick_supabase/brick_supabase.dart';
// ignore: unused_import, unused_shown_name, unnecessary_import
import 'package:pizza_shoppe/brick/models/pizza.model.dart'; // GENERATED CODE DO NOT EDIT
import 'package:pizza_shoppe/brick/models/customer.model.dart'; // GENERATED CODE DO NOT EDIT
// ignore: unused_import
import 'dart:convert';
import 'package:brick_sqlite/brick_sqlite.dart'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,48 @@ part of 'schema.g.dart';

// The migration version must **always** mirror the file name

const List<MigrationCommand> _migration_20240906052847_up = [
InsertTable('_brick_Customer_pizzas'),
const List<MigrationCommand> _migration_20240920063917_up = [
InsertTable('Customer'),
InsertTable('Pizza'),
InsertForeignKey(
'_brick_Customer_pizzas',
'Customer',
foreignKeyColumn: 'l_Customer_brick_id',
onDeleteCascade: true,
onDeleteSetDefault: false,
),
InsertForeignKey(
'_brick_Customer_pizzas',
'Pizza',
foreignKeyColumn: 'f_Pizza_brick_id',
onDeleteCascade: true,
onDeleteSetDefault: false,
),
InsertColumn('id', Column.varchar, onTable: 'Customer', unique: true),
InsertColumn('first_name', Column.varchar, onTable: 'Customer'),
InsertColumn('last_name', Column.varchar, onTable: 'Customer'),
InsertColumn('id', Column.varchar, onTable: 'Pizza', unique: true),
InsertColumn('frozen', Column.boolean, onTable: 'Pizza'),
CreateIndex(
columns: ['l_Customer_brick_id', 'f_Pizza_brick_id'],
onTable: '_brick_Customer_pizzas',
unique: true,
InsertForeignKey(
'Pizza',
'Customer',
foreignKeyColumn: 'customer_Customer_brick_id',
onDeleteCascade: false,
onDeleteSetDefault: false,
),
];

const List<MigrationCommand> _migration_20240906052847_down = [
DropTable('_brick_Customer_pizzas'),
const List<MigrationCommand> _migration_20240920063917_down = [
DropTable('Customer'),
DropTable('Pizza'),
DropColumn('l_Customer_brick_id', onTable: '_brick_Customer_pizzas'),
DropColumn('f_Pizza_brick_id', onTable: '_brick_Customer_pizzas'),
DropColumn('id', onTable: 'Customer'),
DropColumn('first_name', onTable: 'Customer'),
DropColumn('last_name', onTable: 'Customer'),
DropColumn('id', onTable: 'Pizza'),
DropColumn('frozen', onTable: 'Pizza'),
DropIndex('index__brick_Customer_pizzas_on_l_Customer_brick_id_f_Pizza_brick_id'),
DropColumn('customer_Customer_brick_id', onTable: 'Pizza'),
];

//
// DO NOT EDIT BELOW THIS LINE
//

@Migratable(
version: '20240906052847',
up: _migration_20240906052847_up,
down: _migration_20240906052847_down,
version: '20240920063917',
up: _migration_20240920063917_up,
down: _migration_20240920063917_down,
)
class Migration20240906052847 extends Migration {
const Migration20240906052847()
class Migration20240920063917 extends Migration {
const Migration20240920063917()
: super(
version: 20240906052847,
up: _migration_20240906052847_up,
down: _migration_20240906052847_down,
version: 20240920063917,
up: _migration_20240920063917_up,
down: _migration_20240920063917_down,
);
}
29 changes: 9 additions & 20 deletions example_supabase/lib/brick/db/schema.g.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
// GENERATED CODE DO NOT EDIT
// This file should be version controlled
import 'package:brick_sqlite/db.dart';
part '20240906052847.migration.dart';
part '20240920063917.migration.dart';

/// All intelligently-generated migrations from all `@Migratable` classes on disk
final migrations = <Migration>{const Migration20240920034504()};
final migrations = <Migration>{const Migration20240920063917()};

/// A consumable database structure including the latest generated migration.
final schema = Schema(20240906052847, generatorVersion: 1, tables: <SchemaTable>{
SchemaTable('_brick_Customer_pizzas', columns: <SchemaColumn>{
SchemaColumn('_brick_id', Column.integer,
autoincrement: true, nullable: false, isPrimaryKey: true),
SchemaColumn('l_Customer_brick_id', Column.integer,
isForeignKey: true,
foreignTableName: 'Customer',
onDeleteCascade: true,
onDeleteSetDefault: false),
SchemaColumn('f_Pizza_brick_id', Column.integer,
isForeignKey: true,
foreignTableName: 'Pizza',
onDeleteCascade: true,
onDeleteSetDefault: false)
}, indices: <SchemaIndex>{
SchemaIndex(columns: ['l_Customer_brick_id', 'f_Pizza_brick_id'], unique: true)
}),
final schema = Schema(20240920063917, generatorVersion: 1, tables: <SchemaTable>{
SchemaTable('Customer', columns: <SchemaColumn>{
SchemaColumn('_brick_id', Column.integer,
autoincrement: true, nullable: false, isPrimaryKey: true),
Expand All @@ -35,6 +19,11 @@ final schema = Schema(20240906052847, generatorVersion: 1, tables: <SchemaTable>
SchemaColumn('_brick_id', Column.integer,
autoincrement: true, nullable: false, isPrimaryKey: true),
SchemaColumn('id', Column.varchar, unique: true),
SchemaColumn('frozen', Column.boolean)
SchemaColumn('frozen', Column.boolean),
SchemaColumn('customer_Customer_brick_id', Column.integer,
isForeignKey: true,
foreignTableName: 'Customer',
onDeleteCascade: false,
onDeleteSetDefault: false)
}, indices: <SchemaIndex>{})
});
Loading

0 comments on commit a029e62

Please sign in to comment.