From 9952cf8ee6f30ac7ebd60eee62c05be481d0e61b Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 3 Oct 2020 15:08:39 +0000 Subject: [PATCH] Make SQLite compatible patches Bug: T264492 Change-Id: I622b177015740ca5f6f625250efa3d4ad71be448 --- sql/sqlite/patch-add_generic_fields.sql | 23 +++++++++++++++++++ .../patch-remove_module_specific_fields.sql | 17 ++++++++++++++ .../UpdateTables.php | 8 ++++--- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 sql/sqlite/patch-add_generic_fields.sql create mode 100644 sql/sqlite/patch-remove_module_specific_fields.sql diff --git a/sql/sqlite/patch-add_generic_fields.sql b/sql/sqlite/patch-add_generic_fields.sql new file mode 100644 index 00000000..d5307f51 --- /dev/null +++ b/sql/sqlite/patch-add_generic_fields.sql @@ -0,0 +1,23 @@ +CREATE TABLE /*_*/oathauth_users_tmp ( + -- User ID + id int not null primary key, + + -- Secret key + secret text NULL DEFAULT NULL, + + -- Scratch tokens + scratch_tokens blob NULL DEFAULT NULL, + + -- Module user has selected + module text not null, + + -- Data + data blob null +); + +INSERT INTO /*_*/oathauth_users_tmp (id, secret, scratch_tokens, module, data) + SELECT id, secret, scratch_tokens, '', null FROM /*_*/oathauth_users; + +DROP TABLE /*_*/oathauth_users; + +ALTER TABLE /*_*/oathauth_users_tmp RENAME TO /*_*/oathauth_users; diff --git a/sql/sqlite/patch-remove_module_specific_fields.sql b/sql/sqlite/patch-remove_module_specific_fields.sql new file mode 100644 index 00000000..ed472324 --- /dev/null +++ b/sql/sqlite/patch-remove_module_specific_fields.sql @@ -0,0 +1,17 @@ +CREATE TABLE /*_*/oathauth_users_tmp ( + -- User ID + id int not null primary key, + + -- Module user has selected + module text not null, + + -- Data + data blob null +); + +INSERT INTO /*_*/oathauth_users_tmp (id, module, data) + SELECT id, module, data FROM /*_*/oathauth_users; + +DROP TABLE /*_*/oathauth_users; + +ALTER TABLE /*_*/oathauth_users_tmp RENAME TO /*_*/oathauth_users; diff --git a/src/Hook/LoadExtensionSchemaUpdates/UpdateTables.php b/src/Hook/LoadExtensionSchemaUpdates/UpdateTables.php index 4366428f..06f1bfc9 100644 --- a/src/Hook/LoadExtensionSchemaUpdates/UpdateTables.php +++ b/src/Hook/LoadExtensionSchemaUpdates/UpdateTables.php @@ -40,7 +40,8 @@ class UpdateTables { } protected function execute() { - switch ( $this->updater->getDB()->getType() ) { + $type = $this->updater->getDB()->getType(); + switch ( $type ) { case 'mysql': case 'sqlite': $this->updater->addExtensionTable( 'oathauth_users', "{$this->base}/sql/mysql/tables.sql" ); @@ -50,10 +51,11 @@ class UpdateTables { 'secret_reset', "{$this->base}/sql/mysql/patch-remove_reset.sql" ); + $this->updater->addExtensionField( 'oathauth_users', 'module', - "{$this->base}/sql/mysql/patch-add_generic_fields.sql" + "{$this->base}/sql/{$type}/patch-add_generic_fields.sql" ); $this->updater->addExtensionUpdate( @@ -62,7 +64,7 @@ class UpdateTables { $this->updater->dropExtensionField( 'oathauth_users', 'secret', - "{$this->base}/sql/mysql/patch-remove_module_specific_fields.sql" + "{$this->base}/sql/{$type}/patch-remove_module_specific_fields.sql" ); $this->updater->addExtensionUpdate(