Switch database setup to use migrations.

This commit is contained in:
Joachim Bauch 2021-11-22 16:05:08 +01:00
parent 4e6009c530
commit 660fbeae76
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 41 additions and 52 deletions

View file

@ -1,52 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<database>
<name>*dbname*</name>
<create>true</create>
<overwrite>false</overwrite>
<charset>utf8</charset>
<table>
<name>*dbprefix*pdfdraw_items</name>
<declaration>
<field>
<name>file_id</name>
<type>text</type>
<notnull>true</notnull>
</field>
<field>
<name>page</name>
<type>integer</type>
<notnull>true</notnull>
</field>
<field>
<name>name</name>
<type>text</type>
<notnull>true</notnull>
</field>
<field>
<name>data</name>
<type>clob</type>
<notnull>true</notnull>
</field>
<index>
<name>fileid_index</name>
<field>
<name>file_id</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>fileid_name_index</name>
<primary>true</primary>
<unique>true</unique>
<field>
<name>file_id</name>
<sorting>ascending</sorting>
</field>
<field>
<name>name</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>
</database>

View file

@ -0,0 +1,41 @@
<?php
namespace OCA\Pdfdraw\Migration;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
class Version1000Date20211122150107 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
* @since 13.0.0
*/
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('pdfdraw_items')) {
$table = $schema->createTable('pdfdraw_items');
$table->addColumn('file_id', 'string', [
'notnull' => true,
]);
$table->addColumn('page', 'integer', [
'notnull' => true,
]);
$table->addColumn('name', 'string', [
'notnull' => true,
]);
$table->addColumn('data', 'text', [
'notnull' => true,
]);
$table->setPrimaryKey(['file_id', 'name']);
$table->addIndex(['file_id'], 'fileid_index');
}
return $schema;
}
}