You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Version13000Date20170718121200.php 28KB

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