Enforce stable ride ID uniqueness on fresh databases
This commit is contained in:
parent
b9ed2d629b
commit
83c6bb6ad8
|
|
@ -23,9 +23,11 @@ class AppDatabase extends _$AppDatabase {
|
||||||
@override
|
@override
|
||||||
MigrationStrategy get migration => MigrationStrategy(
|
MigrationStrategy get migration => MigrationStrategy(
|
||||||
onCreate: (Migrator m) async {
|
onCreate: (Migrator m) async {
|
||||||
// cloudRideId is part of the generated Drift schema. Do not manually
|
|
||||||
// ALTER this column here: generated sources are authoritative for fresh DBs.
|
|
||||||
await m.createAll();
|
await m.createAll();
|
||||||
|
// cloudRideId is generated by Drift on fresh databases. The uniqueness
|
||||||
|
// constraint is kept as an explicit index so the nullable migration
|
||||||
|
// column remains compatible with older generated source versions.
|
||||||
|
await customStatement('CREATE UNIQUE INDEX IF NOT EXISTS rides_cloud_ride_id_idx ON rides(cloud_ride_id)');
|
||||||
},
|
},
|
||||||
onUpgrade: (Migrator m, int from, int to) async {
|
onUpgrade: (Migrator m, int from, int to) async {
|
||||||
if (from < 2) {
|
if (from < 2) {
|
||||||
|
|
@ -77,7 +79,7 @@ class AppDatabase extends _$AppDatabase {
|
||||||
// Existing MotorCloud records were keyed by the deterministic legacy
|
// Existing MotorCloud records were keyed by the deterministic legacy
|
||||||
// identity ride_<localId>_<UTC yyyyMMdd_HHmmss>. Preserve that identity
|
// identity ride_<localId>_<UTC yyyyMMdd_HHmmss>. Preserve that identity
|
||||||
// for pre-v6 rides so their cloud records remain addressable. New rides
|
// for pre-v6 rides so their cloud records remain addressable. New rides
|
||||||
// receive an reinstall-safe random stable ID in startRide().
|
// receive a reinstall-safe random stable ID in startRide().
|
||||||
final rows = await customSelect('SELECT id, start_time FROM rides WHERE cloud_ride_id IS NULL').get();
|
final rows = await customSelect('SELECT id, start_time FROM rides WHERE cloud_ride_id IS NULL').get();
|
||||||
for (final row in rows) {
|
for (final row in rows) {
|
||||||
final id = row.data['id'];
|
final id = row.data['id'];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue