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

View File

@ -70,13 +70,31 @@ class Version200000Date20220924015634 extends SimpleMigrationStep
}
$table = $schema->getTable('memories');
// Drop all indicies with UID
if ($table->hasIndex('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');
}
if (!$table->hasIndex('memories_fileid_index')) {
$table->addUniqueIndex(['fileid'], 'memories_fileid_index');
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -46,28 +46,42 @@ class Version401100Date20230208181533 extends SimpleMigrationStep
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
// Add lat lon to memories
$table = $schema->getTable('memories');
if (!$table->hasColumn('lat')) {
$table->addColumn('lat', Types::DECIMAL, [
'notnull' => false,
'default' => null,
'precision' => 8,
'scale' => 6,
]);
$table->addColumn('lon', Types::DECIMAL, [
'notnull' => false,
'default' => null,
'precision' => 9,
'scale' => 6,
]);
$table->addIndex(['lat', 'lon'], 'memories_lat_lon_index');
// Add lat lon and cluster to memories
if ($schema->hasTable('memories')) {
$table = $schema->getTable('memories');
$table->addColumn('mapcluster', Types::INTEGER, [
'notnull' => false,
'default' => null,
]);
$table->addIndex(['mapcluster'], 'memories_mapcluster_index');
if (!$table->hasColumn('lat')) {
$table->addColumn('lat', Types::DECIMAL, [
'notnull' => false,
'default' => null,
'precision' => 8,
'scale' => 6,
]);
}
if (!$table->hasColumn('lon')) {
$table->addColumn('lon', Types::DECIMAL, [
'notnull' => false,
'default' => null,
'precision' => 9,
'scale' => 6,
]);
}
if (!$table->hasColumn('mapcluster')) {
$table->addColumn('mapcluster', Types::INTEGER, [
'notnull' => false,
'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');
}
}
// Add clusters table

View File

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

View File

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