migrations: make them idempotent

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/807/merge
Varun Patil 2023-10-07 08:45:35 -07:00
parent 255ef832ac
commit 6be0cef3cd
10 changed files with 127 additions and 66 deletions

View File

@ -46,11 +46,13 @@ class Version000000Date20220812163631 extends SimpleMigrationStep
'autoincrement' => true, 'autoincrement' => true,
'notnull' => true, 'notnull' => true,
]); ]);
$table->addColumn('uid', 'string', [
// dropped in Version200000Date20220924015634 // dropped in Version200000Date20220924015634
'notnull' => true, // $table->addColumn('uid', 'string', [
'length' => 64, // 'notnull' => true,
]); // 'length' => 64,
// ]);
$table->addColumn('datetaken', Types::DATETIME, [ $table->addColumn('datetaken', Types::DATETIME, [
'notnull' => false, 'notnull' => false,
]); ]);
@ -65,14 +67,19 @@ class Version000000Date20220812163631 extends SimpleMigrationStep
'notnull' => false, 'notnull' => false,
'default' => false, 'default' => false,
]); ]);
$table->addColumn('mtime', Types::INTEGER, [
// Version505001Date20230828155021
$table->addColumn('mtime', Types::BIGINT, [
'notnull' => true, 'notnull' => true,
'length' => 20,
]); ]);
$table->setPrimaryKey(['id']); $table->setPrimaryKey(['id']);
$table->addIndex(['uid'], 'memories_uid_index');
$table->addIndex(['uid', 'dayid'], 'memories_ud_index'); // All these indices are dropped in Version200000Date20220924015634
$table->addUniqueIndex(['uid', 'fileid'], 'memories_day_uf_ui'); // $table->addIndex(['uid'], 'memories_uid_index');
// $table->addIndex(['uid', 'dayid'], 'memories_ud_index');
// $table->addUniqueIndex(['uid', 'fileid'], 'memories_day_uf_ui');
} }
return $schema; return $schema;

View File

@ -70,13 +70,31 @@ class Version200000Date20220924015634 extends SimpleMigrationStep
} }
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
// Drop all indicies with UID
if ($table->hasIndex('memories_uid_index')) { if ($table->hasIndex('memories_uid_index')) {
$table->dropIndex('memories_uid_index'); $table->dropIndex('memories_uid_index');
$table->dropIndex('memories_ud_index'); }
$table->dropIndex('memories_day_uf_ui');
$table->dropColumn('uid');
if ($table->hasIndex('memories_ud_index')) {
$table->dropIndex('memories_ud_index');
}
if ($table->hasIndex('memories_day_uf_ui')) {
$table->dropIndex('memories_day_uf_ui');
}
// Drop UID column
if ($table->hasColumn('uid')) {
$table->dropColumn('uid');
}
// Add new indicies
if (!$table->hasIndex('memories_dayid_index')) {
$table->addIndex(['dayid'], 'memories_dayid_index'); $table->addIndex(['dayid'], 'memories_dayid_index');
}
if (!$table->hasIndex('memories_fileid_index')) {
$table->addUniqueIndex(['fileid'], 'memories_fileid_index'); $table->addUniqueIndex(['fileid'], 'memories_fileid_index');
} }

View File

@ -52,14 +52,19 @@ class Version400000Date20221015121115 extends SimpleMigrationStep
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
if (!$table->hasColumn('w')) {
$table->addColumn('w', Types::INTEGER, [ $table->addColumn('w', Types::INTEGER, [
'notnull' => true, 'notnull' => true,
'default' => 0, 'default' => 0,
]); ]);
}
if (!$table->hasColumn('h')) {
$table->addColumn('h', Types::INTEGER, [ $table->addColumn('h', Types::INTEGER, [
'notnull' => true, 'notnull' => true,
'default' => 0, 'default' => 0,
]); ]);
}
return $schema; return $schema;
} }

View File

@ -60,14 +60,17 @@ class Version400503Date20221101033144 extends SimpleMigrationStep
// The problem is objectid in systemtags is VARCHAR(64) while fileid in // The problem is objectid in systemtags is VARCHAR(64) while fileid in
// filecache and memories is BIGINT(20), so a join is extremely slow, // filecache and memories is BIGINT(20), so a join is extremely slow,
// because the entire tags table must be scanned for the conversion. // because the entire tags table must be scanned for the conversion.
if (!$table->hasColumn('objectid')) {
$table->addColumn('objectid', 'string', [ $table->addColumn('objectid', 'string', [
'notnull' => true, 'notnull' => true,
'length' => 64, 'length' => 64,
'default' => '0', // set to real value in postSchemaChange 'default' => '0', // set to real value in postSchemaChange
]); ]);
}
if (!$table->hasIndex('memories_objectid_index')) {
$table->addIndex(['objectid'], 'memories_objectid_index'); $table->addIndex(['objectid'], 'memories_objectid_index');
}
return $schema; return $schema;
} }

View File

@ -47,11 +47,13 @@ class Version400604Date20221107205439 extends SimpleMigrationStep
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
if (!$table->hasColumn('exif')) {
$table->addColumn('exif', 'text', [ $table->addColumn('exif', 'text', [
'notnull' => false, 'notnull' => false,
'length' => 65535, 'length' => 65535,
'default' => '', 'default' => '',
]); ]);
}
return $schema; return $schema;
} }

View File

@ -48,10 +48,12 @@ class Version400700Date20221110030909 extends SimpleMigrationStep
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
if (!$table->hasColumn('video_duration')) {
$table->addColumn('video_duration', Types::INTEGER, [ $table->addColumn('video_duration', Types::INTEGER, [
'notnull' => true, 'notnull' => true,
'default' => 0, 'default' => 0,
]); ]);
}
return $schema; return $schema;
} }

View File

@ -46,6 +46,7 @@ class Version401100Date20230206002744 extends SimpleMigrationStep
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();
// Create places table
if (!$schema->hasTable('memories_places')) { if (!$schema->hasTable('memories_places')) {
$table = $schema->createTable('memories_places'); $table = $schema->createTable('memories_places');
$table->addColumn('id', 'integer', [ $table->addColumn('id', 'integer', [
@ -65,6 +66,7 @@ class Version401100Date20230206002744 extends SimpleMigrationStep
$table->addIndex(['osm_id'], 'memories_places_osm_id_index'); $table->addIndex(['osm_id'], 'memories_places_osm_id_index');
} }
// Create planet table
if (!$schema->hasTable('memories_planet')) { if (!$schema->hasTable('memories_planet')) {
$table = $schema->createTable('memories_planet'); $table = $schema->createTable('memories_planet');
$table->addColumn('id', 'integer', [ $table->addColumn('id', 'integer', [

View File

@ -46,8 +46,10 @@ class Version401100Date20230208181533 extends SimpleMigrationStep
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();
// Add lat lon to memories // Add lat lon and cluster to memories
if ($schema->hasTable('memories')) {
$table = $schema->getTable('memories'); $table = $schema->getTable('memories');
if (!$table->hasColumn('lat')) { if (!$table->hasColumn('lat')) {
$table->addColumn('lat', Types::DECIMAL, [ $table->addColumn('lat', Types::DECIMAL, [
'notnull' => false, 'notnull' => false,
@ -55,20 +57,32 @@ class Version401100Date20230208181533 extends SimpleMigrationStep
'precision' => 8, 'precision' => 8,
'scale' => 6, 'scale' => 6,
]); ]);
}
if (!$table->hasColumn('lon')) {
$table->addColumn('lon', Types::DECIMAL, [ $table->addColumn('lon', Types::DECIMAL, [
'notnull' => false, 'notnull' => false,
'default' => null, 'default' => null,
'precision' => 9, 'precision' => 9,
'scale' => 6, 'scale' => 6,
]); ]);
$table->addIndex(['lat', 'lon'], 'memories_lat_lon_index'); }
if (!$table->hasColumn('mapcluster')) {
$table->addColumn('mapcluster', Types::INTEGER, [ $table->addColumn('mapcluster', Types::INTEGER, [
'notnull' => false, 'notnull' => false,
'default' => null, 'default' => null,
]); ]);
}
if (!$table->hasIndex('memories_lat_lon_index')) {
$table->addIndex(['lat', 'lon'], 'memories_lat_lon_index');
}
if (!$table->hasIndex('memories_mapcluster_index')) {
$table->addIndex(['mapcluster'], 'memories_mapcluster_index'); $table->addIndex(['mapcluster'], 'memories_mapcluster_index');
} }
}
// Add clusters table // Add clusters table
if (!$schema->hasTable('memories_mapclusters')) { if (!$schema->hasTable('memories_mapclusters')) {

View File

@ -45,11 +45,14 @@ class Version401300Date20230328012131 extends SimpleMigrationStep
/** @var ISchemaWrapper $schema */ /** @var ISchemaWrapper $schema */
$schema = $schemaClosure(); $schema = $schemaClosure();
// Add lat lon to memories // Add other_names to planet database
$table = $schema->getTable('memories_planet'); $table = $schema->getTable('memories_planet');
if (!$table->hasColumn('other_names')) {
$table->addColumn('other_names', 'text', [ $table->addColumn('other_names', 'text', [
'notnull' => false, 'notnull' => false,
]); ]);
}
return $schema; return $schema;
} }

View File

@ -45,12 +45,17 @@ class Version502000Date20230530052850 extends SimpleMigrationStep
$schema = $schemaClosure(); $schema = $schemaClosure();
$table = $schema->getTable('memories_places'); $table = $schema->getTable('memories_places');
if (!$table->hasColumn('mark')) {
$table->addColumn('mark', Types::BOOLEAN, [ $table->addColumn('mark', Types::BOOLEAN, [
'notnull' => false, 'notnull' => false,
'default' => false, 'default' => false,
]); ]);
}
if (!$table->hasIndex('memories_places_id_mk_idx')) {
$table->addIndex(['osm_id', 'mark'], 'memories_places_id_mk_idx'); $table->addIndex(['osm_id', 'mark'], 'memories_places_id_mk_idx');
}
return $schema; return $schema;
} }