Version13000Date20170718121200.php 28 KB

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