Version13000Date20170718121200.php 28 KB

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