Version13000Date20170718121200.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  8. * @author Georg Ehrke <oc.list@georgehrke.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Julius Härtl <jus@bitgrid.net>
  11. * @author Mario Danic <mario@lovelyhq.com>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. *
  16. * @license GNU AGPL version 3 or any later version
  17. *
  18. * This program is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License as
  20. * published by the Free Software Foundation, either version 3 of the
  21. * License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. *
  31. */
  32. namespace OC\Core\Migrations;
  33. use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  34. use OCP\DB\ISchemaWrapper;
  35. use OCP\DB\Types;
  36. use OCP\IDBConnection;
  37. use OCP\Migration\IOutput;
  38. use OCP\Migration\SimpleMigrationStep;
  39. class Version13000Date20170718121200 extends SimpleMigrationStep {
  40. public function __construct(
  41. private IDBConnection $connection,
  42. ) {
  43. }
  44. public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  45. /** @var ISchemaWrapper $schema */
  46. $schema = $schemaClosure();
  47. if (!$schema->hasTable('properties')) {
  48. return;
  49. }
  50. // in case we have a properties table from oc we drop it since we will only migrate
  51. // the dav_properties values in the postSchemaChange step
  52. $table = $schema->getTable('properties');
  53. if ($table->hasColumn('fileid')) {
  54. $qb = $this->connection->getQueryBuilder();
  55. $qb->delete('properties');
  56. $qb->execute();
  57. }
  58. }
  59. /**
  60. * @param IOutput $output
  61. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  62. * @param array $options
  63. * @return null|ISchemaWrapper
  64. * @since 13.0.0
  65. */
  66. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  67. /** @var ISchemaWrapper $schema */
  68. $schema = $schemaClosure();
  69. if (!$schema->hasTable('appconfig')) {
  70. $table = $schema->createTable('appconfig');
  71. $table->addColumn('appid', 'string', [
  72. 'notnull' => true,
  73. 'length' => 32,
  74. 'default' => '',
  75. ]);
  76. $table->addColumn('configkey', 'string', [
  77. 'notnull' => true,
  78. 'length' => 64,
  79. 'default' => '',
  80. ]);
  81. $table->addColumn('configvalue', 'text', [
  82. 'notnull' => false,
  83. ]);
  84. $table->setPrimaryKey(['appid', 'configkey']);
  85. $table->addIndex(['configkey'], 'appconfig_config_key_index');
  86. $table->addIndex(['appid'], 'appconfig_appid_key');
  87. }
  88. if (!$schema->hasTable('storages')) {
  89. $table = $schema->createTable('storages');
  90. $table->addColumn('id', 'string', [
  91. 'notnull' => false,
  92. 'length' => 64,
  93. ]);
  94. $table->addColumn('numeric_id', Types::BIGINT, [
  95. 'autoincrement' => true,
  96. 'notnull' => true,
  97. 'length' => 20,
  98. ]);
  99. $table->addColumn('available', 'integer', [
  100. 'notnull' => true,
  101. 'default' => 1,
  102. ]);
  103. $table->addColumn('last_checked', 'integer', [
  104. 'notnull' => false,
  105. ]);
  106. $table->setPrimaryKey(['numeric_id']);
  107. $table->addUniqueIndex(['id'], 'storages_id_index');
  108. }
  109. if (!$schema->hasTable('mounts')) {
  110. $table = $schema->createTable('mounts');
  111. $table->addColumn('id', 'integer', [
  112. 'autoincrement' => true,
  113. 'notnull' => true,
  114. 'length' => 4,
  115. ]);
  116. $table->addColumn('storage_id', Types::BIGINT, [
  117. 'notnull' => true,
  118. 'length' => 20,
  119. ]);
  120. $table->addColumn('root_id', Types::BIGINT, [
  121. 'notnull' => true,
  122. 'length' => 20,
  123. ]);
  124. $table->addColumn('user_id', 'string', [
  125. 'notnull' => true,
  126. 'length' => 64,
  127. ]);
  128. $table->addColumn('mount_point', 'string', [
  129. 'notnull' => true,
  130. 'length' => 4000,
  131. ]);
  132. $table->addColumn('mount_id', Types::BIGINT, [
  133. 'notnull' => false,
  134. 'length' => 20,
  135. ]);
  136. $table->setPrimaryKey(['id']);
  137. $table->addIndex(['user_id'], 'mounts_user_index');
  138. $table->addIndex(['storage_id'], 'mounts_storage_index');
  139. $table->addIndex(['root_id'], 'mounts_root_index');
  140. $table->addIndex(['mount_id'], 'mounts_mount_id_index');
  141. $table->addIndex(['user_id', 'root_id', 'mount_point'], 'mounts_user_root_path_index', [], ['lengths' => [null, null, 128]]);
  142. } else {
  143. $table = $schema->getTable('mounts');
  144. $table->addColumn('mount_id', Types::BIGINT, [
  145. 'notnull' => false,
  146. 'length' => 20,
  147. ]);
  148. if (!$table->hasIndex('mounts_mount_id_index')) {
  149. $table->addIndex(['mount_id'], 'mounts_mount_id_index');
  150. }
  151. }
  152. if (!$schema->hasTable('mimetypes')) {
  153. $table = $schema->createTable('mimetypes');
  154. $table->addColumn('id', Types::BIGINT, [
  155. 'autoincrement' => true,
  156. 'notnull' => true,
  157. 'length' => 20,
  158. ]);
  159. $table->addColumn('mimetype', 'string', [
  160. 'notnull' => true,
  161. 'length' => 255,
  162. 'default' => '',
  163. ]);
  164. $table->setPrimaryKey(['id']);
  165. $table->addUniqueIndex(['mimetype'], 'mimetype_id_index');
  166. }
  167. if (!$schema->hasTable('filecache')) {
  168. $table = $schema->createTable('filecache');
  169. $table->addColumn('fileid', Types::BIGINT, [
  170. 'autoincrement' => true,
  171. 'notnull' => true,
  172. 'length' => 20,
  173. ]);
  174. $table->addColumn('storage', Types::BIGINT, [
  175. 'notnull' => true,
  176. 'length' => 20,
  177. 'default' => 0,
  178. ]);
  179. $table->addColumn('path', 'string', [
  180. 'notnull' => false,
  181. 'length' => 4000,
  182. ]);
  183. $table->addColumn('path_hash', 'string', [
  184. 'notnull' => true,
  185. 'length' => 32,
  186. 'default' => '',
  187. ]);
  188. $table->addColumn('parent', Types::BIGINT, [
  189. 'notnull' => true,
  190. 'length' => 20,
  191. 'default' => 0,
  192. ]);
  193. $table->addColumn('name', 'string', [
  194. 'notnull' => false,
  195. 'length' => 250,
  196. ]);
  197. $table->addColumn('mimetype', Types::BIGINT, [
  198. 'notnull' => true,
  199. 'length' => 20,
  200. 'default' => 0,
  201. ]);
  202. $table->addColumn('mimepart', Types::BIGINT, [
  203. 'notnull' => true,
  204. 'length' => 20,
  205. 'default' => 0,
  206. ]);
  207. $table->addColumn('size', 'bigint', [
  208. 'notnull' => true,
  209. 'length' => 8,
  210. 'default' => 0,
  211. ]);
  212. $table->addColumn('mtime', Types::BIGINT, [
  213. 'notnull' => true,
  214. 'length' => 20,
  215. 'default' => 0,
  216. ]);
  217. $table->addColumn('storage_mtime', Types::BIGINT, [
  218. 'notnull' => true,
  219. 'length' => 20,
  220. 'default' => 0,
  221. ]);
  222. $table->addColumn('encrypted', 'integer', [
  223. 'notnull' => true,
  224. 'length' => 4,
  225. 'default' => 0,
  226. ]);
  227. $table->addColumn('unencrypted_size', 'bigint', [
  228. 'notnull' => true,
  229. 'length' => 8,
  230. 'default' => 0,
  231. ]);
  232. $table->addColumn('etag', 'string', [
  233. 'notnull' => false,
  234. 'length' => 40,
  235. ]);
  236. $table->addColumn('permissions', 'integer', [
  237. 'notnull' => false,
  238. 'length' => 4,
  239. 'default' => 0,
  240. ]);
  241. $table->addColumn('checksum', 'string', [
  242. 'notnull' => false,
  243. 'length' => 255,
  244. ]);
  245. $table->setPrimaryKey(['fileid']);
  246. $table->addUniqueIndex(['storage', 'path_hash'], 'fs_storage_path_hash');
  247. $table->addIndex(['parent', 'name'], 'fs_parent_name_hash');
  248. $table->addIndex(['storage', 'mimetype'], 'fs_storage_mimetype');
  249. $table->addIndex(['storage', 'mimepart'], 'fs_storage_mimepart');
  250. $table->addIndex(['storage', 'size', 'fileid'], 'fs_storage_size');
  251. $table->addIndex(['fileid', 'storage', 'size'], 'fs_id_storage_size');
  252. $table->addIndex(['parent'], 'fs_parent');
  253. $table->addIndex(['mtime'], 'fs_mtime');
  254. $table->addIndex(['size'], 'fs_size');
  255. if (!$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
  256. $table->addIndex(['storage', 'path'], 'fs_storage_path_prefix', [], ['lengths' => [null, 64]]);
  257. }
  258. }
  259. if (!$schema->hasTable('group_user')) {
  260. $table = $schema->createTable('group_user');
  261. $table->addColumn('gid', 'string', [
  262. 'notnull' => true,
  263. 'length' => 64,
  264. 'default' => '',
  265. ]);
  266. $table->addColumn('uid', 'string', [
  267. 'notnull' => true,
  268. 'length' => 64,
  269. 'default' => '',
  270. ]);
  271. $table->setPrimaryKey(['gid', 'uid']);
  272. $table->addIndex(['uid'], 'gu_uid_index');
  273. }
  274. if (!$schema->hasTable('group_admin')) {
  275. $table = $schema->createTable('group_admin');
  276. $table->addColumn('gid', 'string', [
  277. 'notnull' => true,
  278. 'length' => 64,
  279. 'default' => '',
  280. ]);
  281. $table->addColumn('uid', 'string', [
  282. 'notnull' => true,
  283. 'length' => 64,
  284. 'default' => '',
  285. ]);
  286. $table->setPrimaryKey(['gid', 'uid']);
  287. $table->addIndex(['uid'], 'group_admin_uid');
  288. }
  289. if (!$schema->hasTable('groups')) {
  290. $table = $schema->createTable('groups');
  291. $table->addColumn('gid', 'string', [
  292. 'notnull' => true,
  293. 'length' => 64,
  294. 'default' => '',
  295. ]);
  296. $table->setPrimaryKey(['gid']);
  297. }
  298. if (!$schema->hasTable('preferences')) {
  299. $table = $schema->createTable('preferences');
  300. $table->addColumn('userid', 'string', [
  301. 'notnull' => true,
  302. 'length' => 64,
  303. 'default' => '',
  304. ]);
  305. $table->addColumn('appid', 'string', [
  306. 'notnull' => true,
  307. 'length' => 32,
  308. 'default' => '',
  309. ]);
  310. $table->addColumn('configkey', 'string', [
  311. 'notnull' => true,
  312. 'length' => 64,
  313. 'default' => '',
  314. ]);
  315. $table->addColumn('configvalue', 'text', [
  316. 'notnull' => false,
  317. ]);
  318. $table->setPrimaryKey(['userid', 'appid', 'configkey']);
  319. $table->addIndex(['appid', 'configkey'], 'preferences_app_key');
  320. }
  321. if (!$schema->hasTable('properties')) {
  322. $table = $schema->createTable('properties');
  323. $table->addColumn('id', 'integer', [
  324. 'autoincrement' => true,
  325. 'notnull' => true,
  326. 'length' => 4,
  327. ]);
  328. $table->addColumn('userid', 'string', [
  329. 'notnull' => true,
  330. 'length' => 64,
  331. 'default' => '',
  332. ]);
  333. $table->addColumn('propertypath', 'string', [
  334. 'notnull' => true,
  335. 'length' => 255,
  336. 'default' => '',
  337. ]);
  338. $table->addColumn('propertyname', 'string', [
  339. 'notnull' => true,
  340. 'length' => 255,
  341. 'default' => '',
  342. ]);
  343. $table->addColumn('propertyvalue', 'text', [
  344. 'notnull' => true,
  345. ]);
  346. $table->setPrimaryKey(['id']);
  347. // Dropped in Version29000Date20240131122720 because property_index is redundant with properties_path_index
  348. // $table->addIndex(['userid'], 'property_index');
  349. $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
  350. $table->addIndex(['propertypath'], 'properties_pathonly_index');
  351. } else {
  352. $table = $schema->getTable('properties');
  353. if ($table->hasColumn('propertytype')) {
  354. $table->dropColumn('propertytype');
  355. }
  356. if ($table->hasColumn('fileid')) {
  357. $table->dropColumn('fileid');
  358. }
  359. if (!$table->hasColumn('propertypath')) {
  360. $table->addColumn('propertypath', 'string', [
  361. 'notnull' => true,
  362. 'length' => 255,
  363. ]);
  364. }
  365. if (!$table->hasColumn('userid')) {
  366. $table->addColumn('userid', 'string', [
  367. 'notnull' => false,
  368. 'length' => 64,
  369. 'default' => '',
  370. ]);
  371. }
  372. }
  373. if (!$schema->hasTable('share')) {
  374. $table = $schema->createTable('share');
  375. $table->addColumn('id', 'integer', [
  376. 'autoincrement' => true,
  377. 'notnull' => true,
  378. 'length' => 4,
  379. ]);
  380. $table->addColumn('share_type', 'smallint', [
  381. 'notnull' => true,
  382. 'length' => 1,
  383. 'default' => 0,
  384. ]);
  385. $table->addColumn('share_with', 'string', [
  386. 'notnull' => false,
  387. 'length' => 255,
  388. ]);
  389. $table->addColumn('password', 'string', [
  390. 'notnull' => false,
  391. 'length' => 255,
  392. ]);
  393. $table->addColumn('uid_owner', 'string', [
  394. 'notnull' => true,
  395. 'length' => 64,
  396. 'default' => '',
  397. ]);
  398. $table->addColumn('uid_initiator', 'string', [
  399. 'notnull' => false,
  400. 'length' => 64,
  401. ]);
  402. $table->addColumn('parent', 'integer', [
  403. 'notnull' => false,
  404. 'length' => 4,
  405. ]);
  406. $table->addColumn('item_type', 'string', [
  407. 'notnull' => true,
  408. 'length' => 64,
  409. 'default' => '',
  410. ]);
  411. $table->addColumn('item_source', 'string', [
  412. 'notnull' => false,
  413. 'length' => 255,
  414. ]);
  415. $table->addColumn('item_target', 'string', [
  416. 'notnull' => false,
  417. 'length' => 255,
  418. ]);
  419. $table->addColumn('file_source', 'integer', [
  420. 'notnull' => false,
  421. 'length' => 4,
  422. ]);
  423. $table->addColumn('file_target', 'string', [
  424. 'notnull' => false,
  425. 'length' => 512,
  426. ]);
  427. $table->addColumn('permissions', 'smallint', [
  428. 'notnull' => true,
  429. 'length' => 1,
  430. 'default' => 0,
  431. ]);
  432. $table->addColumn('stime', 'bigint', [
  433. 'notnull' => true,
  434. 'length' => 8,
  435. 'default' => 0,
  436. ]);
  437. $table->addColumn('accepted', 'smallint', [
  438. 'notnull' => true,
  439. 'length' => 1,
  440. 'default' => 0,
  441. ]);
  442. $table->addColumn('expiration', 'datetime', [
  443. 'notnull' => false,
  444. ]);
  445. $table->addColumn('token', 'string', [
  446. 'notnull' => false,
  447. 'length' => 32,
  448. ]);
  449. $table->addColumn('mail_send', 'smallint', [
  450. 'notnull' => true,
  451. 'length' => 1,
  452. 'default' => 0,
  453. ]);
  454. $table->addColumn('share_name', 'string', [
  455. 'notnull' => false,
  456. 'length' => 64,
  457. ]);
  458. $table->setPrimaryKey(['id']);
  459. $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
  460. $table->addIndex(['file_source'], 'file_source_index');
  461. $table->addIndex(['token'], 'token_index');
  462. $table->addIndex(['share_with'], 'share_with_index');
  463. $table->addIndex(['parent'], 'parent_index');
  464. $table->addIndex(['uid_owner'], 'owner_index');
  465. $table->addIndex(['uid_initiator'], 'initiator_index');
  466. } else {
  467. $table = $schema->getTable('share');
  468. if (!$table->hasColumn('password')) {
  469. $table->addColumn('password', 'string', [
  470. 'notnull' => false,
  471. 'length' => 255,
  472. ]);
  473. }
  474. }
  475. if (!$schema->hasTable('jobs')) {
  476. $table = $schema->createTable('jobs');
  477. $table->addColumn('id', 'integer', [
  478. 'autoincrement' => true,
  479. 'notnull' => true,
  480. 'length' => 4,
  481. 'unsigned' => true,
  482. ]);
  483. $table->addColumn('class', 'string', [
  484. 'notnull' => true,
  485. 'length' => 255,
  486. 'default' => '',
  487. ]);
  488. $table->addColumn('argument', 'string', [
  489. 'notnull' => true,
  490. 'length' => 4000,
  491. 'default' => '',
  492. ]);
  493. $table->addColumn('last_run', 'integer', [
  494. 'notnull' => false,
  495. 'default' => 0,
  496. ]);
  497. $table->addColumn('last_checked', 'integer', [
  498. 'notnull' => false,
  499. 'default' => 0,
  500. ]);
  501. $table->addColumn('reserved_at', 'integer', [
  502. 'notnull' => false,
  503. 'default' => 0,
  504. ]);
  505. $table->addColumn('execution_duration', 'integer', [
  506. 'notnull' => true,
  507. 'default' => 0,
  508. ]);
  509. $table->setPrimaryKey(['id']);
  510. $table->addIndex(['class'], 'job_class_index');
  511. $table->addIndex(['last_checked', 'reserved_at'], 'job_lastcheck_reserved');
  512. }
  513. if (!$schema->hasTable('users')) {
  514. $table = $schema->createTable('users');
  515. $table->addColumn('uid', 'string', [
  516. 'notnull' => true,
  517. 'length' => 64,
  518. 'default' => '',
  519. ]);
  520. $table->addColumn('displayname', 'string', [
  521. 'notnull' => false,
  522. 'length' => 64,
  523. ]);
  524. $table->addColumn('password', 'string', [
  525. 'notnull' => true,
  526. 'length' => 255,
  527. 'default' => '',
  528. ]);
  529. $table->setPrimaryKey(['uid']);
  530. }
  531. if (!$schema->hasTable('authtoken')) {
  532. $table = $schema->createTable('authtoken');
  533. $table->addColumn('id', 'integer', [
  534. 'autoincrement' => true,
  535. 'notnull' => true,
  536. 'length' => 4,
  537. 'unsigned' => true,
  538. ]);
  539. $table->addColumn('uid', 'string', [
  540. 'notnull' => true,
  541. 'length' => 64,
  542. 'default' => '',
  543. ]);
  544. $table->addColumn('login_name', 'string', [
  545. 'notnull' => true,
  546. 'length' => 64,
  547. 'default' => '',
  548. ]);
  549. $table->addColumn('password', 'text', [
  550. 'notnull' => false,
  551. ]);
  552. $table->addColumn('name', 'text', [
  553. 'notnull' => true,
  554. 'default' => '',
  555. ]);
  556. $table->addColumn('token', 'string', [
  557. 'notnull' => true,
  558. 'length' => 200,
  559. 'default' => '',
  560. ]);
  561. $table->addColumn('type', 'smallint', [
  562. 'notnull' => false,
  563. 'length' => 2,
  564. 'default' => 0,
  565. 'unsigned' => true,
  566. ]);
  567. $table->addColumn('remember', 'smallint', [
  568. 'notnull' => false,
  569. 'length' => 1,
  570. 'default' => 0,
  571. 'unsigned' => true,
  572. ]);
  573. $table->addColumn('last_activity', 'integer', [
  574. 'notnull' => false,
  575. 'length' => 4,
  576. 'default' => 0,
  577. 'unsigned' => true,
  578. ]);
  579. $table->addColumn('last_check', 'integer', [
  580. 'notnull' => false,
  581. 'length' => 4,
  582. 'default' => 0,
  583. 'unsigned' => true,
  584. ]);
  585. $table->addColumn('scope', 'text', [
  586. 'notnull' => false,
  587. ]);
  588. $table->setPrimaryKey(['id']);
  589. $table->addUniqueIndex(['token'], 'authtoken_token_index');
  590. $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
  591. } else {
  592. $table = $schema->getTable('authtoken');
  593. $table->addColumn('scope', 'text', [
  594. 'notnull' => false,
  595. ]);
  596. }
  597. if (!$schema->hasTable('bruteforce_attempts')) {
  598. $table = $schema->createTable('bruteforce_attempts');
  599. $table->addColumn('id', 'integer', [
  600. 'autoincrement' => true,
  601. 'notnull' => true,
  602. 'length' => 4,
  603. 'unsigned' => true,
  604. ]);
  605. $table->addColumn('action', 'string', [
  606. 'notnull' => true,
  607. 'length' => 64,
  608. 'default' => '',
  609. ]);
  610. $table->addColumn('occurred', 'integer', [
  611. 'notnull' => true,
  612. 'length' => 4,
  613. 'default' => 0,
  614. 'unsigned' => true,
  615. ]);
  616. $table->addColumn('ip', 'string', [
  617. 'notnull' => true,
  618. 'length' => 255,
  619. 'default' => '',
  620. ]);
  621. $table->addColumn('subnet', 'string', [
  622. 'notnull' => true,
  623. 'length' => 255,
  624. 'default' => '',
  625. ]);
  626. $table->addColumn('metadata', 'string', [
  627. 'notnull' => true,
  628. 'length' => 255,
  629. 'default' => '',
  630. ]);
  631. $table->setPrimaryKey(['id']);
  632. $table->addIndex(['ip'], 'bruteforce_attempts_ip');
  633. $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
  634. }
  635. if (!$schema->hasTable('vcategory')) {
  636. $table = $schema->createTable('vcategory');
  637. $table->addColumn('id', 'integer', [
  638. 'autoincrement' => true,
  639. 'notnull' => true,
  640. 'length' => 4,
  641. 'unsigned' => true,
  642. ]);
  643. $table->addColumn('uid', 'string', [
  644. 'notnull' => true,
  645. 'length' => 64,
  646. 'default' => '',
  647. ]);
  648. $table->addColumn('type', 'string', [
  649. 'notnull' => true,
  650. 'length' => 64,
  651. 'default' => '',
  652. ]);
  653. $table->addColumn('category', 'string', [
  654. 'notnull' => true,
  655. 'length' => 255,
  656. 'default' => '',
  657. ]);
  658. $table->setPrimaryKey(['id']);
  659. $table->addIndex(['uid'], 'uid_index');
  660. $table->addIndex(['type'], 'type_index');
  661. $table->addIndex(['category'], 'category_index');
  662. }
  663. if (!$schema->hasTable('vcategory_to_object')) {
  664. $table = $schema->createTable('vcategory_to_object');
  665. $table->addColumn('objid', 'integer', [
  666. 'notnull' => true,
  667. 'length' => 4,
  668. 'default' => 0,
  669. 'unsigned' => true,
  670. ]);
  671. $table->addColumn('categoryid', 'integer', [
  672. 'notnull' => true,
  673. 'length' => 4,
  674. 'default' => 0,
  675. 'unsigned' => true,
  676. ]);
  677. $table->addColumn('type', 'string', [
  678. 'notnull' => true,
  679. 'length' => 64,
  680. 'default' => '',
  681. ]);
  682. $table->setPrimaryKey(['categoryid', 'objid', 'type']);
  683. $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
  684. }
  685. if (!$schema->hasTable('systemtag')) {
  686. $table = $schema->createTable('systemtag');
  687. $table->addColumn('id', 'integer', [
  688. 'autoincrement' => true,
  689. 'notnull' => true,
  690. 'length' => 4,
  691. 'unsigned' => true,
  692. ]);
  693. $table->addColumn('name', 'string', [
  694. 'notnull' => true,
  695. 'length' => 64,
  696. 'default' => '',
  697. ]);
  698. $table->addColumn('visibility', 'smallint', [
  699. 'notnull' => true,
  700. 'length' => 1,
  701. 'default' => 1,
  702. ]);
  703. $table->addColumn('editable', 'smallint', [
  704. 'notnull' => true,
  705. 'length' => 1,
  706. 'default' => 1,
  707. ]);
  708. $table->setPrimaryKey(['id']);
  709. $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
  710. }
  711. if (!$schema->hasTable('systemtag_object_mapping')) {
  712. $table = $schema->createTable('systemtag_object_mapping');
  713. $table->addColumn('objectid', 'string', [
  714. 'notnull' => true,
  715. 'length' => 64,
  716. 'default' => '',
  717. ]);
  718. $table->addColumn('objecttype', 'string', [
  719. 'notnull' => true,
  720. 'length' => 64,
  721. 'default' => '',
  722. ]);
  723. $table->addColumn('systemtagid', 'integer', [
  724. 'notnull' => true,
  725. 'length' => 4,
  726. 'default' => 0,
  727. 'unsigned' => true,
  728. ]);
  729. $table->setPrimaryKey(['objecttype', 'objectid', 'systemtagid'], 'som_pk');
  730. // $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
  731. $table->addIndex(['systemtagid', 'objecttype'], 'systag_by_tagid');
  732. }
  733. if (!$schema->hasTable('systemtag_group')) {
  734. $table = $schema->createTable('systemtag_group');
  735. $table->addColumn('systemtagid', 'integer', [
  736. 'notnull' => true,
  737. 'length' => 4,
  738. 'default' => 0,
  739. 'unsigned' => true,
  740. ]);
  741. $table->addColumn('gid', 'string', [
  742. 'notnull' => true,
  743. ]);
  744. $table->setPrimaryKey(['gid', 'systemtagid']);
  745. }
  746. if (!$schema->hasTable('file_locks')) {
  747. $table = $schema->createTable('file_locks');
  748. $table->addColumn('id', 'integer', [
  749. 'autoincrement' => true,
  750. 'notnull' => true,
  751. 'length' => 4,
  752. 'unsigned' => true,
  753. ]);
  754. $table->addColumn('lock', 'integer', [
  755. 'notnull' => true,
  756. 'length' => 4,
  757. 'default' => 0,
  758. ]);
  759. $table->addColumn('key', 'string', [
  760. 'notnull' => true,
  761. 'length' => 64,
  762. ]);
  763. $table->addColumn('ttl', 'integer', [
  764. 'notnull' => true,
  765. 'length' => 4,
  766. 'default' => -1,
  767. ]);
  768. $table->setPrimaryKey(['id']);
  769. $table->addUniqueIndex(['key'], 'lock_key_index');
  770. $table->addIndex(['ttl'], 'lock_ttl_index');
  771. }
  772. if (!$schema->hasTable('comments')) {
  773. $table = $schema->createTable('comments');
  774. $table->addColumn('id', 'integer', [
  775. 'autoincrement' => true,
  776. 'notnull' => true,
  777. 'length' => 4,
  778. 'unsigned' => true,
  779. ]);
  780. $table->addColumn('parent_id', 'integer', [
  781. 'notnull' => true,
  782. 'length' => 4,
  783. 'default' => 0,
  784. 'unsigned' => true,
  785. ]);
  786. $table->addColumn('topmost_parent_id', 'integer', [
  787. 'notnull' => true,
  788. 'length' => 4,
  789. 'default' => 0,
  790. 'unsigned' => true,
  791. ]);
  792. $table->addColumn('children_count', 'integer', [
  793. 'notnull' => true,
  794. 'length' => 4,
  795. 'default' => 0,
  796. 'unsigned' => true,
  797. ]);
  798. $table->addColumn('actor_type', 'string', [
  799. 'notnull' => true,
  800. 'length' => 64,
  801. 'default' => '',
  802. ]);
  803. $table->addColumn('actor_id', 'string', [
  804. 'notnull' => true,
  805. 'length' => 64,
  806. 'default' => '',
  807. ]);
  808. $table->addColumn('message', 'text', [
  809. 'notnull' => false,
  810. ]);
  811. $table->addColumn('verb', 'string', [
  812. 'notnull' => false,
  813. 'length' => 64,
  814. ]);
  815. $table->addColumn('creation_timestamp', 'datetime', [
  816. 'notnull' => false,
  817. ]);
  818. $table->addColumn('latest_child_timestamp', 'datetime', [
  819. 'notnull' => false,
  820. ]);
  821. $table->addColumn('object_type', 'string', [
  822. 'notnull' => true,
  823. 'length' => 64,
  824. 'default' => '',
  825. ]);
  826. $table->addColumn('object_id', 'string', [
  827. 'notnull' => true,
  828. 'length' => 64,
  829. 'default' => '',
  830. ]);
  831. $table->addColumn('reference_id', 'string', [
  832. 'notnull' => false,
  833. 'length' => 64,
  834. ]);
  835. $table->setPrimaryKey(['id']);
  836. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  837. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  838. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  839. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  840. }
  841. if (!$schema->hasTable('comments_read_markers')) {
  842. $table = $schema->createTable('comments_read_markers');
  843. $table->addColumn('user_id', 'string', [
  844. 'notnull' => true,
  845. 'length' => 64,
  846. 'default' => '',
  847. ]);
  848. $table->addColumn('marker_datetime', 'datetime', [
  849. 'notnull' => false,
  850. ]);
  851. $table->addColumn('object_type', 'string', [
  852. 'notnull' => true,
  853. 'length' => 64,
  854. 'default' => '',
  855. ]);
  856. $table->addColumn('object_id', 'string', [
  857. 'notnull' => true,
  858. 'length' => 64,
  859. 'default' => '',
  860. ]);
  861. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  862. $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
  863. // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  864. }
  865. // if (!$schema->hasTable('credentials')) {
  866. // $table = $schema->createTable('credentials');
  867. // $table->addColumn('user', 'string', [
  868. // 'notnull' => false,
  869. // 'length' => 64,
  870. // ]);
  871. // $table->addColumn('identifier', 'string', [
  872. // 'notnull' => true,
  873. // 'length' => 64,
  874. // ]);
  875. // $table->addColumn('credentials', 'text', [
  876. // 'notnull' => false,
  877. // ]);
  878. // $table->setPrimaryKey(['user', 'identifier']);
  879. // $table->addIndex(['user'], 'credentials_user');
  880. // }
  881. if (!$schema->hasTable('admin_sections')) {
  882. $table = $schema->createTable('admin_sections');
  883. $table->addColumn('id', 'string', [
  884. 'notnull' => true,
  885. 'length' => 64,
  886. ]);
  887. $table->addColumn('class', 'string', [
  888. 'notnull' => true,
  889. 'length' => 255,
  890. 'default' => '',
  891. ]);
  892. $table->addColumn('priority', 'smallint', [
  893. 'notnull' => true,
  894. 'length' => 1,
  895. 'default' => 0,
  896. ]);
  897. $table->setPrimaryKey(['id']);
  898. $table->addUniqueIndex(['class'], 'admin_sections_class');
  899. }
  900. if (!$schema->hasTable('admin_settings')) {
  901. $table = $schema->createTable('admin_settings');
  902. $table->addColumn('id', 'integer', [
  903. 'autoincrement' => true,
  904. 'notnull' => true,
  905. 'length' => 4,
  906. ]);
  907. $table->addColumn('class', 'string', [
  908. 'notnull' => true,
  909. 'length' => 255,
  910. 'default' => '',
  911. ]);
  912. $table->addColumn('section', 'string', [
  913. 'notnull' => false,
  914. 'length' => 64,
  915. ]);
  916. $table->addColumn('priority', 'smallint', [
  917. 'notnull' => true,
  918. 'length' => 1,
  919. 'default' => 0,
  920. ]);
  921. $table->setPrimaryKey(['id']);
  922. $table->addUniqueIndex(['class'], 'admin_settings_class');
  923. $table->addIndex(['section'], 'admin_settings_section');
  924. }
  925. if (!$schema->hasTable('personal_sections')) {
  926. $table = $schema->createTable('personal_sections');
  927. $table->addColumn('id', 'string', [
  928. 'notnull' => true,
  929. 'length' => 64,
  930. ]);
  931. $table->addColumn('class', 'string', [
  932. 'notnull' => true,
  933. 'length' => 255,
  934. 'default' => '',
  935. ]);
  936. $table->addColumn('priority', 'smallint', [
  937. 'notnull' => true,
  938. 'length' => 1,
  939. 'default' => 0,
  940. ]);
  941. $table->setPrimaryKey(['id']);
  942. $table->addUniqueIndex(['class'], 'personal_sections_class');
  943. }
  944. if (!$schema->hasTable('personal_settings')) {
  945. $table = $schema->createTable('personal_settings');
  946. $table->addColumn('id', 'integer', [
  947. 'autoincrement' => true,
  948. 'notnull' => true,
  949. 'length' => 4,
  950. ]);
  951. $table->addColumn('class', 'string', [
  952. 'notnull' => true,
  953. 'length' => 255,
  954. 'default' => '',
  955. ]);
  956. $table->addColumn('section', 'string', [
  957. 'notnull' => false,
  958. 'length' => 64,
  959. ]);
  960. $table->addColumn('priority', 'smallint', [
  961. 'notnull' => true,
  962. 'length' => 1,
  963. 'default' => 0,
  964. ]);
  965. $table->setPrimaryKey(['id']);
  966. $table->addUniqueIndex(['class'], 'personal_settings_class');
  967. $table->addIndex(['section'], 'personal_settings_section');
  968. }
  969. if (!$schema->hasTable('accounts')) {
  970. $table = $schema->createTable('accounts');
  971. $table->addColumn('uid', 'string', [
  972. 'notnull' => true,
  973. 'length' => 64,
  974. 'default' => '',
  975. ]);
  976. $table->addColumn('data', 'text', [
  977. 'notnull' => true,
  978. 'default' => '',
  979. ]);
  980. $table->setPrimaryKey(['uid']);
  981. }
  982. return $schema;
  983. }
  984. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  985. /** @var ISchemaWrapper $schema */
  986. $schema = $schemaClosure();
  987. if (!$schema->hasTable('dav_properties')) {
  988. return;
  989. }
  990. $query = $this->connection->getQueryBuilder();
  991. $query->select('*')
  992. ->from('dav_properties');
  993. $insert = $this->connection->getQueryBuilder();
  994. $insert->insert('properties')
  995. ->setValue('propertypath', $insert->createParameter('propertypath'))
  996. ->setValue('propertyname', $insert->createParameter('propertyname'))
  997. ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
  998. ->setValue('userid', $insert->createParameter('userid'));
  999. $result = $query->execute();
  1000. while ($row = $result->fetch()) {
  1001. preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
  1002. $insert->setParameter('propertypath', (string) $row['propertypath'])
  1003. ->setParameter('propertyname', (string) $row['propertyname'])
  1004. ->setParameter('propertyvalue', (string) $row['propertyvalue'])
  1005. ->setParameter('userid', ($match[2] ?? ''));
  1006. $insert->execute();
  1007. }
  1008. }
  1009. }