1
0

Version13000Date20170718121200.php 28 KB

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