Version13000Date20170718121200.php 27 KB

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