1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-07-22 17:35:52 +00:00

Migrate away from database.xml to new database migrations

This commit is contained in:
Alfred Egger 2020-12-16 21:38:03 +01:00
parent 7ee735c547
commit 2078096ba6
2 changed files with 173 additions and 268 deletions

View File

@ -1,268 +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*ocsms_user_datas</name>
<declaration>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>datakey</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>datavalue</name>
<type>text</type>
<length>64</length>
<notnull>true</notnull>
</field>
<index>
<name>user_datas_user_datakey</name>
<field>
<name>user_id</name>
</field>
<field>
<name>datakey</name>
</field>
</index>
</declaration>
</table>
<table>
<name>*dbprefix*ocsms_smsdatas</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>10</length>
<primary>true</primary>
</field>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>added</name>
<type>timestamp</type>
<notnull>true</notnull>
<default>1970-01-01 00:00:00</default>
</field>
<field>
<name>lastmodified</name>
<type>timestamp</type>
<notnull>true</notnull>
<default>1970-01-01 00:00:00</default>
</field>
<field>
<name>sms_id</name>
<type>integer</type>
<notnull>true</notnull>
<length>5</length>
</field>
<field>
<name>sms_address</name>
<type>text</type>
<notnull>true</notnull>
<length>512</length>
</field>
<field>
<name>sms_msg</name>
<type>text</type>
<notnull>true</notnull>
<length>10240</length>
</field>
<field>
<name>sms_date</name>
<type>integer</type>
<notnull>true</notnull>
<length>10</length>
</field>
<field>
<name>sms_flags</name>
<type>text</type>
<notnull>true</notnull>
<default>00</default>
<length>2</length>
</field>
<field>
<name>sms_mailbox</name>
<type>integer</type>
<notnull>true</notnull>
<length>1</length>
</field>
<field>
<name>sms_type</name>
<type>integer</type>
<notnull>true</notnull>
<length>1</length>
</field>
<index>
<name>smsdata_user_mailbox</name>
<field>
<name>user_id</name>
</field>
<field>
<name>sms_mailbox</name>
</field>
</index>
<index>
<name>smsdata_user_smsid</name>
<field>
<name>user_id</name>
</field>
<field>
<name>sms_id</name>
</field>
</index>
<index>
<name>smsdata_user_mailbox_date</name>
<field>
<name>user_id</name>
</field>
<field>
<name>sms_mailbox</name>
</field>
<field>
<name>sms_date</name>
</field>
</index>
<index>
<name>smsdata_user_mailbox_address</name>
<field>
<name>user_id</name>
</field>
<field>
<name>sms_mailbox</name>
</field>
<field>
<name>sms_address</name>
</field>
</index>
<index>
<name>smsdata_user_mailbox_address_date</name>
<field>
<name>user_id</name>
</field>
<field>
<name>sms_mailbox</name>
</field>
<field>
<name>sms_address</name>
</field>
<field>
<name>sms_date</name>
</field>
</index>
</declaration>
</table>
<table>
<name>*dbprefix*ocsms_sendmessage_queue</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<length>10</length>
<primary>true</primary>
</field>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>sms_address</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>sms_msg</name>
<type>text</type>
<notnull>true</notnull>
<length>2048</length>
</field>
</declaration>
</table>
<table>
<name>*dbprefix*ocsms_conversation_read_states</name>
<declaration>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>phone_number</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>int_date</name>
<type>integer</type>
<length>32</length>
<notnull>true</notnull>
</field>
<index>
<name>sms_conversation_rs_pkey</name>
<field>
<name>user_id</name>
</field>
<field>
<name>phone_number</name>
</field>
</index>
</declaration>
</table>
<table>
<name>*dbprefix*ocsms_config</name>
<declaration>
<field>
<name>user</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>key</name>
<type>text</type>
<notnull>true</notnull>
<length>255</length>
</field>
<field>
<name>value</name>
<type>text</type>
<notnull>false</notnull>
<length>10240</length>
</field>
<index>
<name>config_user_key</name>
<field>
<name>user</name>
</field>
<field>
<name>key</name>
</field>
</index>
</declaration>
</table>
</database>

View File

@ -0,0 +1,173 @@
<?php
declare(strict_types=1);
namespace OCA\Ocsms\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version020109Date20201216203338 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('ocsms_user_datas')) {
$table = $schema->createTable('ocsms_user_datas');
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('datakey', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('datavalue', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addIndex(['user_id', 'datakey'], 'user_datas_user_datakey');
}
if (!$schema->hasTable('ocsms_smsdatas')) {
$table = $schema->createTable('ocsms_smsdatas');
$table->addColumn('id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 10,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('added', 'datetime', [
'notnull' => true,
'default' => '1970-01-01 00:00:00',
]);
$table->addColumn('lastmodified', 'datetime', [
'notnull' => true,
'default' => '1970-01-01 00:00:00',
]);
$table->addColumn('sms_id', 'bigint', [
'notnull' => true,
'length' => 5,
]);
$table->addColumn('sms_address', 'string', [
'notnull' => true,
'length' => 512,
]);
$table->addColumn('sms_msg', 'string', [
'notnull' => true,
'length' => 10240,
]);
$table->addColumn('sms_date', 'bigint', [
'notnull' => true,
'length' => 10,
]);
$table->addColumn('sms_flags', 'string', [
'notnull' => true,
'length' => 2,
'default' => '00',
]);
$table->addColumn('sms_mailbox', 'smallint', [
'notnull' => true,
'length' => 1,
]);
$table->addColumn('sms_type', 'smallint', [
'notnull' => true,
'length' => 1,
]);
$table->setPrimaryKey(['id']);
$table->addIndex(['user_id', 'sms_mailbox'], 'smsdata_user_mailbox');
$table->addIndex(['user_id', 'sms_id'], 'smsdata_user_smsid');
$table->addIndex(['user_id', 'sms_mailbox', 'sms_date'], 'smsdata_user_mailbox_date');
$table->addIndex(['user_id', 'sms_mailbox', 'sms_address'], 'smsdata_user_mailbox_address');
$table->addIndex(['user_id', 'sms_mailbox', 'sms_address', 'sms_date'], 'smsdata_user_mailbox_address_date');
}
if (!$schema->hasTable('ocsms_sendmessage_queue')) {
$table = $schema->createTable('ocsms_sendmessage_queue');
$table->addColumn('id', 'bigint', [
'autoincrement' => true,
'notnull' => true,
'length' => 10,
]);
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('sms_address', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('sms_msg', 'string', [
'notnull' => true,
'length' => 2048,
]);
$table->setPrimaryKey(['id']);
}
if (!$schema->hasTable('ocsms_conversation_read_states')) {
$table = $schema->createTable('ocsms_conversation_read_states');
$table->addColumn('user_id', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('phone_number', 'string', [
'notnull' => true,
'length' => 64,
]);
$table->addColumn('int_date', 'bigint', [
'notnull' => true,
'length' => 32,
]);
$table->addIndex(['user_id', 'phone_number'], 'sms_conversation_rs_pkey');
}
if (!$schema->hasTable('ocsms_config')) {
$table = $schema->createTable('ocsms_config');
$table->addColumn('user', 'string', [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('key', 'string', [
'notnull' => true,
'length' => 255,
]);
$table->addColumn('value', 'string', [
'notnull' => false,
'length' => 10240,
]);
$table->addIndex(['user', 'key'], 'config_user_key');
}
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) {
}
}