123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023 |
- <?php
- /**
- * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
- namespace OC\Core\Migrations;
- use OCP\DB\ISchemaWrapper;
- use OCP\DB\Types;
- use OCP\IDBConnection;
- use OCP\Migration\IOutput;
- use OCP\Migration\SimpleMigrationStep;
- class Version13000Date20170718121200 extends SimpleMigrationStep {
- public function __construct(
- private IDBConnection $connection,
- ) {
- }
- public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
- /** @var ISchemaWrapper $schema */
- $schema = $schemaClosure();
- if (!$schema->hasTable('properties')) {
- return;
- }
- // in case we have a properties table from oc we drop it since we will only migrate
- // the dav_properties values in the postSchemaChange step
- $table = $schema->getTable('properties');
- if ($table->hasColumn('fileid')) {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('properties');
- $qb->execute();
- }
- }
- /**
- * @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('appconfig')) {
- $table = $schema->createTable('appconfig');
- $table->addColumn('appid', 'string', [
- 'notnull' => true,
- 'length' => 32,
- 'default' => '',
- ]);
- $table->addColumn('configkey', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('configvalue', 'text', [
- 'notnull' => false,
- ]);
- $table->setPrimaryKey(['appid', 'configkey']);
- $table->addIndex(['configkey'], 'appconfig_config_key_index');
- $table->addIndex(['appid'], 'appconfig_appid_key');
- }
- if (!$schema->hasTable('storages')) {
- $table = $schema->createTable('storages');
- $table->addColumn('id', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('numeric_id', Types::BIGINT, [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 20,
- ]);
- $table->addColumn('available', 'integer', [
- 'notnull' => true,
- 'default' => 1,
- ]);
- $table->addColumn('last_checked', 'integer', [
- 'notnull' => false,
- ]);
- $table->setPrimaryKey(['numeric_id']);
- $table->addUniqueIndex(['id'], 'storages_id_index');
- }
- if (!$schema->hasTable('mounts')) {
- $table = $schema->createTable('mounts');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- ]);
- $table->addColumn('storage_id', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- ]);
- $table->addColumn('root_id', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- ]);
- $table->addColumn('user_id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- ]);
- $table->addColumn('mount_point', 'string', [
- 'notnull' => true,
- 'length' => 4000,
- ]);
- $table->addColumn('mount_id', Types::BIGINT, [
- 'notnull' => false,
- 'length' => 20,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['user_id'], 'mounts_user_index');
- $table->addIndex(['storage_id'], 'mounts_storage_index');
- $table->addIndex(['root_id'], 'mounts_root_index');
- $table->addIndex(['mount_id'], 'mounts_mount_id_index');
- $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]);
- } else {
- $table = $schema->getTable('mounts');
- if (!$table->hasColumn('mount_id')) {
- $table->addColumn('mount_id', Types::BIGINT, [
- 'notnull' => false,
- 'length' => 20,
- ]);
- }
- if (!$table->hasIndex('mounts_mount_id_index')) {
- $table->addIndex(['mount_id'], 'mounts_mount_id_index');
- }
- }
- if (!$schema->hasTable('mimetypes')) {
- $table = $schema->createTable('mimetypes');
- $table->addColumn('id', Types::BIGINT, [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 20,
- ]);
- $table->addColumn('mimetype', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
- }
- if (!$schema->hasTable('filecache')) {
- $table = $schema->createTable('filecache');
- $table->addColumn('fileid', Types::BIGINT, [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 20,
- ]);
- $table->addColumn('storage', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('path', 'string', [
- 'notnull' => false,
- 'length' => 4000,
- ]);
- $table->addColumn('path_hash', 'string', [
- 'notnull' => true,
- 'length' => 32,
- 'default' => '',
- ]);
- $table->addColumn('parent', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('name', 'string', [
- 'notnull' => false,
- 'length' => 250,
- ]);
- $table->addColumn('mimetype', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('mimepart', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('size', 'bigint', [
- 'notnull' => true,
- 'length' => 8,
- 'default' => 0,
- ]);
- $table->addColumn('mtime', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('storage_mtime', Types::BIGINT, [
- 'notnull' => true,
- 'length' => 20,
- 'default' => 0,
- ]);
- $table->addColumn('encrypted', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- ]);
- $table->addColumn('unencrypted_size', 'bigint', [
- 'notnull' => true,
- 'length' => 8,
- 'default' => 0,
- ]);
- $table->addColumn('etag', 'string', [
- 'notnull' => false,
- 'length' => 40,
- ]);
- $table->addColumn('permissions', 'integer', [
- 'notnull' => false,
- 'length' => 4,
- 'default' => 0,
- ]);
- $table->addColumn('checksum', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- $table->setPrimaryKey(['fileid']);
- $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
- $table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
- $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
- $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
- $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
- $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
- $table->addIndex(['parent'], 'fs_parent');
- $table->addIndex(['name'], 'fs_name_hash');
- $table->addIndex(['mtime'], 'fs_mtime');
- $table->addIndex(['size'], 'fs_size');
- if ($this->connection->getDatabaseProvider() !== IDBConnection::PLATFORM_POSTGRES) {
- $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
- }
- }
- if (!$schema->hasTable('group_user')) {
- $table = $schema->createTable('group_user');
- $table->addColumn('gid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['gid', 'uid']);
- $table->addIndex(['uid'], 'gu_uid_index');
- }
- if (!$schema->hasTable('group_admin')) {
- $table = $schema->createTable('group_admin');
- $table->addColumn('gid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['gid', 'uid']);
- $table->addIndex(['uid'], 'group_admin_uid');
- }
- if (!$schema->hasTable('groups')) {
- $table = $schema->createTable('groups');
- $table->addColumn('gid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['gid']);
- }
- if (!$schema->hasTable('preferences')) {
- $table = $schema->createTable('preferences');
- $table->addColumn('userid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('appid', 'string', [
- 'notnull' => true,
- 'length' => 32,
- 'default' => '',
- ]);
- $table->addColumn('configkey', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('configvalue', 'text', [
- 'notnull' => false,
- ]);
- $table->setPrimaryKey(['userid', 'appid', 'configkey']);
- $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
- }
- if (!$schema->hasTable('properties')) {
- $table = $schema->createTable('properties');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- ]);
- $table->addColumn('userid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('propertypath', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('propertyname', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('propertyvalue', 'text', [
- 'notnull' => true,
- ]);
- $table->setPrimaryKey(['id']);
- // Dropped in Version29000Date20240131122720 because property_index is redundant with properties_path_index
- // $table->addIndex(['userid'], 'property_index');
- $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
- $table->addIndex(['propertypath'], 'properties_pathonly_index');
- } else {
- $table = $schema->getTable('properties');
- if ($table->hasColumn('propertytype')) {
- $table->dropColumn('propertytype');
- }
- if ($table->hasColumn('fileid')) {
- $table->dropColumn('fileid');
- }
- if (!$table->hasColumn('propertypath')) {
- $table->addColumn('propertypath', 'string', [
- 'notnull' => true,
- 'length' => 255,
- ]);
- }
- if (!$table->hasColumn('userid')) {
- $table->addColumn('userid', 'string', [
- 'notnull' => false,
- 'length' => 64,
- 'default' => '',
- ]);
- }
- }
- if (!$schema->hasTable('share')) {
- $table = $schema->createTable('share');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- ]);
- $table->addColumn('share_type', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->addColumn('share_with', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- $table->addColumn('password', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- $table->addColumn('uid_owner', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('uid_initiator', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('parent', 'integer', [
- 'notnull' => false,
- 'length' => 4,
- ]);
- $table->addColumn('item_type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('item_source', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- $table->addColumn('item_target', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- $table->addColumn('file_source', 'integer', [
- 'notnull' => false,
- 'length' => 4,
- ]);
- $table->addColumn('file_target', 'string', [
- 'notnull' => false,
- 'length' => 512,
- ]);
- $table->addColumn('permissions', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->addColumn('stime', 'bigint', [
- 'notnull' => true,
- 'length' => 8,
- 'default' => 0,
- ]);
- $table->addColumn('accepted', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->addColumn('expiration', 'datetime', [
- 'notnull' => false,
- ]);
- $table->addColumn('token', 'string', [
- 'notnull' => false,
- 'length' => 32,
- ]);
- $table->addColumn('mail_send', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->addColumn('share_name', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
- $table->addIndex(['file_source'], 'file_source_index');
- $table->addIndex(['token'], 'token_index');
- $table->addIndex(['share_with'], 'share_with_index');
- $table->addIndex(['parent'], 'parent_index');
- $table->addIndex(['uid_owner'], 'owner_index');
- $table->addIndex(['uid_initiator'], 'initiator_index');
- } else {
- $table = $schema->getTable('share');
- if (!$table->hasColumn('password')) {
- $table->addColumn('password', 'string', [
- 'notnull' => false,
- 'length' => 255,
- ]);
- }
- }
- if (!$schema->hasTable('jobs')) {
- $table = $schema->createTable('jobs');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('class', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('argument', 'string', [
- 'notnull' => true,
- 'length' => 4000,
- 'default' => '',
- ]);
- $table->addColumn('last_run', 'integer', [
- 'notnull' => false,
- 'default' => 0,
- ]);
- $table->addColumn('last_checked', 'integer', [
- 'notnull' => false,
- 'default' => 0,
- ]);
- $table->addColumn('reserved_at', 'integer', [
- 'notnull' => false,
- 'default' => 0,
- ]);
- $table->addColumn('execution_duration', 'integer', [
- 'notnull' => true,
- 'default' => 0,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['class'], 'job_class_index');
- $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
- }
- if (!$schema->hasTable('users')) {
- $table = $schema->createTable('users');
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('displayname', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('password', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['uid']);
- }
- if (!$schema->hasTable('authtoken')) {
- $table = $schema->createTable('authtoken');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('login_name', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('password', 'text', [
- 'notnull' => false,
- ]);
- $table->addColumn('name', 'text', [
- 'notnull' => true,
- 'default' => '',
- ]);
- $table->addColumn('token', 'string', [
- 'notnull' => true,
- 'length' => 200,
- 'default' => '',
- ]);
- $table->addColumn('type', 'smallint', [
- 'notnull' => false,
- 'length' => 2,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('remember', 'smallint', [
- 'notnull' => false,
- 'length' => 1,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('last_activity', 'integer', [
- 'notnull' => false,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('last_check', 'integer', [
- 'notnull' => false,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('scope', 'text', [
- 'notnull' => false,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['token'], 'authtoken_token_index');
- $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
- } else {
- $table = $schema->getTable('authtoken');
- $table->addColumn('scope', 'text', [
- 'notnull' => false,
- ]);
- }
- if (!$schema->hasTable('bruteforce_attempts')) {
- $table = $schema->createTable('bruteforce_attempts');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('action', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('occurred', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('ip', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('subnet', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('metadata', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['ip'], 'bruteforce_attempts_ip');
- $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
- }
- if (!$schema->hasTable('vcategory')) {
- $table = $schema->createTable('vcategory');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('category', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['uid'], 'uid_index');
- $table->addIndex(['type'], 'type_index');
- $table->addIndex(['category'], 'category_index');
- }
- if (!$schema->hasTable('vcategory_to_object')) {
- $table = $schema->createTable('vcategory_to_object');
- $table->addColumn('objid', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('categoryid', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['categoryid', 'objid', 'type']);
- $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
- }
- if (!$schema->hasTable('systemtag')) {
- $table = $schema->createTable('systemtag');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('name', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('visibility', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 1,
- ]);
- $table->addColumn('editable', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 1,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
- }
- if (!$schema->hasTable('systemtag_object_mapping')) {
- $table = $schema->createTable('systemtag_object_mapping');
- $table->addColumn('objectid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('objecttype', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('systemtagid', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
- // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
- $table->addIndex(['systemtagid', 'objecttype'], 'systag_by_tagid');
- }
- if (!$schema->hasTable('systemtag_group')) {
- $table = $schema->createTable('systemtag_group');
- $table->addColumn('systemtagid', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('gid', 'string', [
- 'notnull' => true,
- ]);
- $table->setPrimaryKey(['gid', 'systemtagid']);
- }
- if (!$schema->hasTable('file_locks')) {
- $table = $schema->createTable('file_locks');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('lock', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- ]);
- $table->addColumn('key', 'string', [
- 'notnull' => true,
- 'length' => 64,
- ]);
- $table->addColumn('ttl', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => -1,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['key'], 'lock_key_index');
- $table->addIndex(['ttl'], 'lock_ttl_index');
- }
- if (!$schema->hasTable('comments')) {
- $table = $schema->createTable('comments');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- 'unsigned' => true,
- ]);
- $table->addColumn('parent_id', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('topmost_parent_id', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('children_count', 'integer', [
- 'notnull' => true,
- 'length' => 4,
- 'default' => 0,
- 'unsigned' => true,
- ]);
- $table->addColumn('actor_type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('actor_id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('message', 'text', [
- 'notnull' => false,
- ]);
- $table->addColumn('verb', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('creation_timestamp', 'datetime', [
- 'notnull' => false,
- ]);
- $table->addColumn('latest_child_timestamp', 'datetime', [
- 'notnull' => false,
- ]);
- $table->addColumn('object_type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('object_id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('reference_id', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addIndex(['parent_id'], 'comments_parent_id_index');
- $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
- $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
- $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
- }
- if (!$schema->hasTable('comments_read_markers')) {
- $table = $schema->createTable('comments_read_markers');
- $table->addColumn('user_id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('marker_datetime', 'datetime', [
- 'notnull' => false,
- ]);
- $table->addColumn('object_type', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('object_id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
- $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
- // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
- }
- // if (!$schema->hasTable('credentials')) {
- // $table = $schema->createTable('credentials');
- // $table->addColumn('user', 'string', [
- // 'notnull' => false,
- // 'length' => 64,
- // ]);
- // $table->addColumn('identifier', 'string', [
- // 'notnull' => true,
- // 'length' => 64,
- // ]);
- // $table->addColumn('credentials', 'text', [
- // 'notnull' => false,
- // ]);
- // $table->setPrimaryKey(['user', 'identifier']);
- // $table->addIndex(['user'], 'credentials_user');
- // }
- if (!$schema->hasTable('admin_sections')) {
- $table = $schema->createTable('admin_sections');
- $table->addColumn('id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- ]);
- $table->addColumn('class', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('priority', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['class'], 'admin_sections_class');
- }
- if (!$schema->hasTable('admin_settings')) {
- $table = $schema->createTable('admin_settings');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- ]);
- $table->addColumn('class', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('section', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('priority', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['class'], 'admin_settings_class');
- $table->addIndex(['section'], 'admin_settings_section');
- }
- if (!$schema->hasTable('personal_sections')) {
- $table = $schema->createTable('personal_sections');
- $table->addColumn('id', 'string', [
- 'notnull' => true,
- 'length' => 64,
- ]);
- $table->addColumn('class', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('priority', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['class'], 'personal_sections_class');
- }
- if (!$schema->hasTable('personal_settings')) {
- $table = $schema->createTable('personal_settings');
- $table->addColumn('id', 'integer', [
- 'autoincrement' => true,
- 'notnull' => true,
- 'length' => 4,
- ]);
- $table->addColumn('class', 'string', [
- 'notnull' => true,
- 'length' => 255,
- 'default' => '',
- ]);
- $table->addColumn('section', 'string', [
- 'notnull' => false,
- 'length' => 64,
- ]);
- $table->addColumn('priority', 'smallint', [
- 'notnull' => true,
- 'length' => 1,
- 'default' => 0,
- ]);
- $table->setPrimaryKey(['id']);
- $table->addUniqueIndex(['class'], 'personal_settings_class');
- $table->addIndex(['section'], 'personal_settings_section');
- }
- if (!$schema->hasTable('accounts')) {
- $table = $schema->createTable('accounts');
- $table->addColumn('uid', 'string', [
- 'notnull' => true,
- 'length' => 64,
- 'default' => '',
- ]);
- $table->addColumn('data', 'text', [
- 'notnull' => true,
- 'default' => '',
- ]);
- $table->setPrimaryKey(['uid']);
- }
- return $schema;
- }
- public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
- /** @var ISchemaWrapper $schema */
- $schema = $schemaClosure();
- if (!$schema->hasTable('dav_properties')) {
- return;
- }
- $query = $this->connection->getQueryBuilder();
- $query->select('*')
- ->from('dav_properties');
- $insert = $this->connection->getQueryBuilder();
- $insert->insert('properties')
- ->setValue('propertypath', $insert->createParameter('propertypath'))
- ->setValue('propertyname', $insert->createParameter('propertyname'))
- ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
- ->setValue('userid', $insert->createParameter('userid'));
- $result = $query->execute();
- while ($row = $result->fetch()) {
- preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
- $insert->setParameter('propertypath', (string) $row['propertypath'])
- ->setParameter('propertyname', (string) $row['propertyname'])
- ->setParameter('propertyvalue', (string) $row['propertyvalue'])
- ->setParameter('userid', ($match[2] ?? ''));
- $insert->execute();
- }
- }
- }
|