Skip to content

Commit

Permalink
Fix and improve database migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
leepeuker committed Jul 1, 2023
1 parent 8aad533 commit 3c5092b
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Phinx\Migration\AbstractMigration;

final class AddPlexColumns extends AbstractMigration
final class AddPlexOAuthColumnsToUserTable extends AbstractMigration
{
public function down() : void
{
Expand All @@ -29,4 +29,4 @@ public function up() : void
SQL,
);
}
}
}
103 changes: 95 additions & 8 deletions db/migrations/sqlite/20230627162519_AddPlexColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,79 @@ public function down() : void
`email` TEXT NOT NULL,
`name` TEXT NOT NULL,
`password` TEXT NOT NULL ,
`is_admin` TINYINT(1) DEFAULT 0,
`dashboard_visible_rows` TEXT DEFAULT NULL,
`dashboard_extended_rows` TEXT DEFAULT NULL,
`dashboard_order_rows` TEXT DEFAULT NULL,
`privacy_level` INTEGER DEFAULT 1,
`date_format_id` INTEGER DEFAULT 0,
`trakt_user_name` TEXT,
`plex_webhook_uuid` TEXT,
`jellyfin_webhook_uuid` TEXT,
`emby_webhook_uuid` TEXT,
`trakt_client_id` TEXT,
`jellyfin_scrobble_views` INTEGER DEFAULT 1,
`emby_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_ratings` INTEGER DEFAULT 0,
`watchlist_automatic_removal_enabled` INTEGER DEFAULT 0,
`core_account_changes_disabled` INTEGER DEFAULT 0,
`created_at` TEXT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`email`),
UNIQUE (`name`)
UNIQUE (`name`)
)
SQL,
);
$this->execute('INSERT INTO `tmp_user` (id, email, name, password, privacy_level, date_format_id, trakt_user_name, plex_webhook_uuid, jellyfin_webhook_uuid, trakt_client_id, jellyfin_scrobble_views, plex_scrobble_views, plex_scrobble_ratings, core_account_changes_disabled, created_at) SELECT `id`, `email`, `name`, `password`, `privacy_level`, `date_format_id`, `trakt_user_name`, `plex_webhook_uuid`, `jellyfin_webhook_uuid`, `trakt_client_id`, `jellyfin_scrobble_views`, `plex_scrobble_views`, `plex_scrobble_ratings`, `core_account_changes_disabled`, `created_at` FROM user');

$this->execute(
'INSERT INTO `tmp_user` (
`id`,
`email`,
`name`,
`password`,
`is_admin`,
`dashboard_visible_rows`,
`dashboard_extended_rows`,
`dashboard_order_rows`,
`privacy_level`,
`date_format_id`,
`trakt_user_name`,
`plex_webhook_uuid`,
`jellyfin_webhook_uuid`,
`emby_webhook_uuid`,
`trakt_client_id`,
`jellyfin_scrobble_views`,
`emby_scrobble_views`,
`plex_scrobble_views`,
`plex_scrobble_ratings`,
`watchlist_automatic_removal_enabled`,
`core_account_changes_disabled`,
`created_at`
) SELECT
`id`,
`email`,
`name`,
`password`,
`is_admin`,
`dashboard_visible_rows`,
`dashboard_extended_rows`,
`dashboard_order_rows`,
`privacy_level`,
`date_format_id`,
`trakt_user_name`,
`plex_webhook_uuid`,
`jellyfin_webhook_uuid`,
`emby_webhook_uuid`,
`trakt_client_id`,
`jellyfin_scrobble_views`,
`emby_scrobble_views`,
`plex_scrobble_views`,
`plex_scrobble_ratings`,
`watchlist_automatic_removal_enabled`,
`core_account_changes_disabled`,
`created_at` FROM user',
);
$this->execute('DROP TABLE `user`');
$this->execute('ALTER TABLE `tmp_user` RENAME TO `user`');
}
Expand All @@ -44,30 +99,62 @@ public function up() : void
`email` TEXT NOT NULL,
`name` TEXT NOT NULL,
`password` TEXT NOT NULL ,
`is_admin` TINYINT(1) DEFAULT 0,
`dashboard_visible_rows` TEXT DEFAULT NULL,
`dashboard_extended_rows` TEXT DEFAULT NULL,
`dashboard_order_rows` TEXT DEFAULT NULL,
`privacy_level` INTEGER DEFAULT 1,
`date_format_id` INTEGER DEFAULT 0,
`trakt_user_name` TEXT,
`plex_webhook_uuid` TEXT,
`jellyfin_webhook_uuid` TEXT,
`emby_webhook_uuid` TEXT,
`trakt_client_id` TEXT,
`jellyfin_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_ratings` INTEGER DEFAULT 0,
`plex_client_id` TEXT DEFAULT NULL,
`plex_client_temporary_code` TEXT DEFAULT NULL,
`plex_access_token` TEXT DEFAULT NULL,
`plex_account_id` TEXT DEFAULT NULL,
`plex_server_url` TEXT DEFAULT NULL,
`jellyfin_scrobble_views` INTEGER DEFAULT 1,
`emby_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_views` INTEGER DEFAULT 1,
`plex_scrobble_ratings` INTEGER DEFAULT 0,
`watchlist_automatic_removal_enabled` INTEGER DEFAULT 0,
`core_account_changes_disabled` INTEGER DEFAULT 0,
`created_at` TEXT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE (`email`),
UNIQUE (`name`)
UNIQUE (`name`)
)
SQL,
);
$this->execute('INSERT INTO `tmp_user` (id, email, name, password, privacy_level, date_format_id, trakt_user_name, plex_webhook_uuid, jellyfin_webhook_uuid, trakt_client_id, jellyfin_scrobble_views, plex_scrobble_views, plex_scrobble_ratings, core_account_changes_disabled, created_at) SELECT * FROM user');
$this->execute(
'INSERT INTO `tmp_user` (
`id`,
`email`,
`name`,
`password`,
`is_admin`,
`dashboard_visible_rows`,
`dashboard_extended_rows`,
`dashboard_order_rows`,
`privacy_level`,
`date_format_id`,
`trakt_user_name`,
`plex_webhook_uuid`,
`jellyfin_webhook_uuid`,
`emby_webhook_uuid`,
`trakt_client_id`,
`jellyfin_scrobble_views`,
`emby_scrobble_views`,
`plex_scrobble_views`,
`plex_scrobble_ratings`,
`watchlist_automatic_removal_enabled`,
`core_account_changes_disabled`,
`created_at`
) SELECT * FROM user',
);
$this->execute('DROP TABLE `user`');
$this->execute('ALTER TABLE `tmp_user` RENAME TO `user`');
}
}
}

0 comments on commit 3c5092b

Please sign in to comment.