Merge pull request #6 from sam-19/master

Convert database.xml into a migration step (thanks @sam-19)
This commit is contained in:
e-alfred 2020-06-05 11:01:45 +02:00 committed by GitHub
commit c6cc168d19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 143 additions and 203 deletions

View File

@ -1,203 +0,0 @@
<?xml version="1.0" encoding="ISO-8859-1" ?>
<database>
<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>utf8</charset>
<table>
<name>*dbprefix*reader_bookmarks</name>
<declaration>
<field>
<!-- id -->
<name>id</name>
<type>integer</type>
<notnull>true</notnull>
<autoincrement>true</autoincrement>
<unsigned>true</unsigned>
<primary>true</primary>
<length>8</length>
</field>
<field>
<!-- user ID, maps bookmark to NC/OC user -->
<name>user_id</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<!-- file ID, maps to NC/OC file ID -->
<name>file_id</name>
<type>integer</type>
<notnull>true</notnull>
<unsigned>true</unsigned>
<length>11</length>
</field>
<field>
<!-- type (bookmark, annotation, etc) -->
<name>type</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>32</length>
</field>
<field>
<!-- name -->
<name>name</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>512</length>
</field>
<field>
<!-- value -->
<name>value</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>512</length>
</field>
<field>
<!-- content -->
<name>content</name>
<type>text</type>
<default></default>
<notnull>false</notnull>
<length>4096</length>
</field>
<field>
<!-- last_modified -->
<name>last_modified</name>
<type>integer</type>
<default>0</default>
<length>8</length>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
<index>
<name>reader_bookmarks_file_id_index</name>
<field>
<name>file_id</name>
</field>
</index>
<index>
<name>reader_bookmarks_user_id_index</name>
<field>
<name>user_id</name>
</field>
</index>
<index>
<name>reader_bookmarks_name_index</name>
<field>
<name>name</name>
</field>
</index>
</declaration>
</table>
<table>
<name>*dbprefix*reader_preferences</name>
<declaration>
<field>
<!-- id -->
<name>id</name>
<type>integer</type>
<notnull>true</notnull>
<autoincrement>true</autoincrement>
<unsigned>true</unsigned>
<primary>true</primary>
<length>8</length>
</field>
<field>
<!-- user ID, maps preference to NC/OC user -->
<name>user_id</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<!-- file ID, maps to NC/OC file ID -->
<name>file_id</name>
<type>integer</type>
<notnull>true</notnull>
<unsigned>true</unsigned>
<length>11</length>
</field>
<field>
<!-- scope -->
<name>scope</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>32</length>
</field>
<field>
<!-- name -->
<name>name</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>128</length>
</field>
<field>
<!-- value -->
<name>value</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>4096</length>
</field>
<field>
<!-- last_modified -->
<name>last_modified</name>
<type>integer</type>
<default>0</default>
<length>8</length>
<notnull>false</notnull>
<unsigned>true</unsigned>
</field>
<index>
<name>reader_preferences_file_id_index</name>
<field>
<name>file_id</name>
</field>
</index>
<index>
<name>reader_preferences_user_id_index</name>
<field>
<name>user_id</name>
</field>
</index>
<index>
<name>reader_preferences_scope_index</name>
<field>
<name>scope</name>
</field>
</index>
</declaration>
</table>
</database>

View File

@ -0,0 +1,143 @@
<?php
declare(strict_types=1);
namespace OCA\Epubreader\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Auto-generated migration step
*/
class Version010402Date20200508180941 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
}
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->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) {
}
}