From 6e9812acb070efab01ab120a63c98d6fa02e2319 Mon Sep 17 00:00:00 2001 From: Sampsa Lohi <26563023+sam-19@users.noreply.github.com> Date: Fri, 8 May 2020 21:15:18 +0300 Subject: [PATCH] Convert database.xml into a migration step To avoid serious issues when upgrading the app --- appinfo/database.xml | 203 ------------------ .../Version010402Date20200508180941.php | 143 ++++++++++++ 2 files changed, 143 insertions(+), 203 deletions(-) delete mode 100644 appinfo/database.xml create mode 100644 lib/Migration/Version010402Date20200508180941.php diff --git a/appinfo/database.xml b/appinfo/database.xml deleted file mode 100644 index 562acb3..0000000 --- a/appinfo/database.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - *dbname* - true - false - utf8 - - - *dbprefix*reader_bookmarks - - - - id - integer - true - true - true - true - 8 - - - - - user_id - text - - true - 64 - - - - - file_id - integer - true - true - 11 - - - - - type - text - - true - 32 - - - - - name - text - - true - 512 - - - - - value - text - - true - 512 - - - - - content - text - - false - 4096 - - - - - last_modified - integer - 0 - 8 - false - true - - - - reader_bookmarks_file_id_index - - file_id - - - - - reader_bookmarks_user_id_index - - user_id - - - - - reader_bookmarks_name_index - - name - - - - -
- - - *dbprefix*reader_preferences - - - - id - integer - true - true - true - true - 8 - - - - - user_id - text - - true - 64 - - - - - file_id - integer - true - true - 11 - - - - - scope - text - - true - 32 - - - - - name - text - - true - 128 - - - - - value - text - - true - 4096 - - - - - last_modified - integer - 0 - 8 - false - true - - - - reader_preferences_file_id_index - - file_id - - - - - reader_preferences_user_id_index - - user_id - - - - - reader_preferences_scope_index - - scope - - - - -
- -
diff --git a/lib/Migration/Version010402Date20200508180941.php b/lib/Migration/Version010402Date20200508180941.php new file mode 100644 index 0000000..f66eb8b --- /dev/null +++ b/lib/Migration/Version010402Date20200508180941.php @@ -0,0 +1,143 @@ +hasTable('reader_bookmarks')) { + $table = $schema->createTable('reader_bookmarks'); + $table->addColumn('id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 8, + 'unsigned' => true, + ]); + // user ID, maps bookmark to NC/OC user + $table->addColumn('user_id', 'string', [ + 'notnull' => true, + 'length' => 64, + 'default' => '', + ]); + // file ID, maps to NC/OC file ID + $table->addColumn('file_id', 'bigint', [ + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + // type (bookmark, annotation, etc) + $table->addColumn('type', 'string', [ + 'notnull' => true, + 'length' => 32, + 'default' => '', + ]); + $table->addColumn('name', 'string', [ + 'notnull' => true, + 'length' => 512, + 'default' => '', + ]); + $table->addColumn('value', 'string', [ + 'notnull' => true, + 'length' => 512, + 'default' => '', + ]); + $table->addColumn('content', 'string', [ + 'notnull' => false, + 'length' => 4096, + ]); + $table->addColumn('last_modified', 'bigint', [ + 'notnull' => false, + 'length' => 8, + 'default' => 0, + 'unsigned' => true, + ]); + $table->setPrimaryKey(['id']); + $table->addIndex(['file_id'], 'reader_bookmarks_file_id_index'); + $table->addIndex(['user_id'], 'reader_bookmarks_user_id_index'); + $table->addIndex(['name'], 'reader_bookmarks_name_index'); + } + + if (!$schema->hasTable('reader_preferences')) { + $table = $schema->createTable('reader_preferences'); + $table->addColumn('id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 8, + 'unsigned' => true, + ]); + // user ID, maps preference to NC/OC user + $table->addColumn('user_id', 'string', [ + 'notnull' => true, + 'length' => 64, + 'default' => '', + ]); + // file ID, maps to NC/OC file ID + $table->addColumn('file_id', 'bigint', [ + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('scope', 'string', [ + 'notnull' => true, + 'length' => 32, + 'default' => '', + ]); + $table->addColumn('name', 'string', [ + 'notnull' => true, + 'length' => 128, + 'default' => '', + ]); + $table->addColumn('value', 'string', [ + 'notnull' => true, + 'length' => 4096, + 'default' => '', + ]); + $table->addColumn('last_modified', 'bigint', [ + 'notnull' => false, + 'length' => 8, + 'default' => 0, + 'unsigned' => true, + ]); + $table->setPrimaryKey(['id']); + $table->addIndex(['file_id'], 'reader_preferences_file_id_index'); + $table->addIndex(['user_id'], 'reader_preferences_user_id_index'); + $table->addIndex(['scope'], 'reader_preferences_scope_index'); + } + return $schema; + } + + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + */ + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { + } +}