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. $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. }
  731. if (!$schema->hasTable('systemtag_group')) {
  732. $table = $schema->createTable('systemtag_group');
  733. $table->addColumn('systemtagid', 'integer', [
  734. 'notnull' => true,
  735. 'length' => 4,
  736. 'default' => 0,
  737. 'unsigned' => true,
  738. ]);
  739. $table->addColumn('gid', 'string', [
  740. 'notnull' => true,
  741. ]);
  742. $table->setPrimaryKey(['gid', 'systemtagid']);
  743. }
  744. if (!$schema->hasTable('file_locks')) {
  745. $table = $schema->createTable('file_locks');
  746. $table->addColumn('id', 'integer', [
  747. 'autoincrement' => true,
  748. 'notnull' => true,
  749. 'length' => 4,
  750. 'unsigned' => true,
  751. ]);
  752. $table->addColumn('lock', 'integer', [
  753. 'notnull' => true,
  754. 'length' => 4,
  755. 'default' => 0,
  756. ]);
  757. $table->addColumn('key', 'string', [
  758. 'notnull' => true,
  759. 'length' => 64,
  760. ]);
  761. $table->addColumn('ttl', 'integer', [
  762. 'notnull' => true,
  763. 'length' => 4,
  764. 'default' => -1,
  765. ]);
  766. $table->setPrimaryKey(['id']);
  767. $table->addUniqueIndex(['key'], 'lock_key_index');
  768. $table->addIndex(['ttl'], 'lock_ttl_index');
  769. }
  770. if (!$schema->hasTable('comments')) {
  771. $table = $schema->createTable('comments');
  772. $table->addColumn('id', 'integer', [
  773. 'autoincrement' => true,
  774. 'notnull' => true,
  775. 'length' => 4,
  776. 'unsigned' => true,
  777. ]);
  778. $table->addColumn('parent_id', 'integer', [
  779. 'notnull' => true,
  780. 'length' => 4,
  781. 'default' => 0,
  782. 'unsigned' => true,
  783. ]);
  784. $table->addColumn('topmost_parent_id', 'integer', [
  785. 'notnull' => true,
  786. 'length' => 4,
  787. 'default' => 0,
  788. 'unsigned' => true,
  789. ]);
  790. $table->addColumn('children_count', 'integer', [
  791. 'notnull' => true,
  792. 'length' => 4,
  793. 'default' => 0,
  794. 'unsigned' => true,
  795. ]);
  796. $table->addColumn('actor_type', 'string', [
  797. 'notnull' => true,
  798. 'length' => 64,
  799. 'default' => '',
  800. ]);
  801. $table->addColumn('actor_id', 'string', [
  802. 'notnull' => true,
  803. 'length' => 64,
  804. 'default' => '',
  805. ]);
  806. $table->addColumn('message', 'text', [
  807. 'notnull' => false,
  808. ]);
  809. $table->addColumn('verb', 'string', [
  810. 'notnull' => false,
  811. 'length' => 64,
  812. ]);
  813. $table->addColumn('creation_timestamp', 'datetime', [
  814. 'notnull' => false,
  815. ]);
  816. $table->addColumn('latest_child_timestamp', 'datetime', [
  817. 'notnull' => false,
  818. ]);
  819. $table->addColumn('object_type', 'string', [
  820. 'notnull' => true,
  821. 'length' => 64,
  822. 'default' => '',
  823. ]);
  824. $table->addColumn('object_id', 'string', [
  825. 'notnull' => true,
  826. 'length' => 64,
  827. 'default' => '',
  828. ]);
  829. $table->addColumn('reference_id', 'string', [
  830. 'notnull' => false,
  831. 'length' => 64,
  832. ]);
  833. $table->setPrimaryKey(['id']);
  834. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  835. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  836. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  837. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  838. }
  839. if (!$schema->hasTable('comments_read_markers')) {
  840. $table = $schema->createTable('comments_read_markers');
  841. $table->addColumn('user_id', 'string', [
  842. 'notnull' => true,
  843. 'length' => 64,
  844. 'default' => '',
  845. ]);
  846. $table->addColumn('marker_datetime', 'datetime', [
  847. 'notnull' => false,
  848. ]);
  849. $table->addColumn('object_type', 'string', [
  850. 'notnull' => true,
  851. 'length' => 64,
  852. 'default' => '',
  853. ]);
  854. $table->addColumn('object_id', 'string', [
  855. 'notnull' => true,
  856. 'length' => 64,
  857. 'default' => '',
  858. ]);
  859. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  860. $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
  861. // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  862. }
  863. // if (!$schema->hasTable('credentials')) {
  864. // $table = $schema->createTable('credentials');
  865. // $table->addColumn('user', 'string', [
  866. // 'notnull' => false,
  867. // 'length' => 64,
  868. // ]);
  869. // $table->addColumn('identifier', 'string', [
  870. // 'notnull' => true,
  871. // 'length' => 64,
  872. // ]);
  873. // $table->addColumn('credentials', 'text', [
  874. // 'notnull' => false,
  875. // ]);
  876. // $table->setPrimaryKey(['user', 'identifier']);
  877. // $table->addIndex(['user'], 'credentials_user');
  878. // }
  879. if (!$schema->hasTable('admin_sections')) {
  880. $table = $schema->createTable('admin_sections');
  881. $table->addColumn('id', 'string', [
  882. 'notnull' => true,
  883. 'length' => 64,
  884. ]);
  885. $table->addColumn('class', 'string', [
  886. 'notnull' => true,
  887. 'length' => 255,
  888. 'default' => '',
  889. ]);
  890. $table->addColumn('priority', 'smallint', [
  891. 'notnull' => true,
  892. 'length' => 1,
  893. 'default' => 0,
  894. ]);
  895. $table->setPrimaryKey(['id']);
  896. $table->addUniqueIndex(['class'], 'admin_sections_class');
  897. }
  898. if (!$schema->hasTable('admin_settings')) {
  899. $table = $schema->createTable('admin_settings');
  900. $table->addColumn('id', 'integer', [
  901. 'autoincrement' => true,
  902. 'notnull' => true,
  903. 'length' => 4,
  904. ]);
  905. $table->addColumn('class', 'string', [
  906. 'notnull' => true,
  907. 'length' => 255,
  908. 'default' => '',
  909. ]);
  910. $table->addColumn('section', 'string', [
  911. 'notnull' => false,
  912. 'length' => 64,
  913. ]);
  914. $table->addColumn('priority', 'smallint', [
  915. 'notnull' => true,
  916. 'length' => 1,
  917. 'default' => 0,
  918. ]);
  919. $table->setPrimaryKey(['id']);
  920. $table->addUniqueIndex(['class'], 'admin_settings_class');
  921. $table->addIndex(['section'], 'admin_settings_section');
  922. }
  923. if (!$schema->hasTable('personal_sections')) {
  924. $table = $schema->createTable('personal_sections');
  925. $table->addColumn('id', 'string', [
  926. 'notnull' => true,
  927. 'length' => 64,
  928. ]);
  929. $table->addColumn('class', 'string', [
  930. 'notnull' => true,
  931. 'length' => 255,
  932. 'default' => '',
  933. ]);
  934. $table->addColumn('priority', 'smallint', [
  935. 'notnull' => true,
  936. 'length' => 1,
  937. 'default' => 0,
  938. ]);
  939. $table->setPrimaryKey(['id']);
  940. $table->addUniqueIndex(['class'], 'personal_sections_class');
  941. }
  942. if (!$schema->hasTable('personal_settings')) {
  943. $table = $schema->createTable('personal_settings');
  944. $table->addColumn('id', 'integer', [
  945. 'autoincrement' => true,
  946. 'notnull' => true,
  947. 'length' => 4,
  948. ]);
  949. $table->addColumn('class', 'string', [
  950. 'notnull' => true,
  951. 'length' => 255,
  952. 'default' => '',
  953. ]);
  954. $table->addColumn('section', 'string', [
  955. 'notnull' => false,
  956. 'length' => 64,
  957. ]);
  958. $table->addColumn('priority', 'smallint', [
  959. 'notnull' => true,
  960. 'length' => 1,
  961. 'default' => 0,
  962. ]);
  963. $table->setPrimaryKey(['id']);
  964. $table->addUniqueIndex(['class'], 'personal_settings_class');
  965. $table->addIndex(['section'], 'personal_settings_section');
  966. }
  967. if (!$schema->hasTable('accounts')) {
  968. $table = $schema->createTable('accounts');
  969. $table->addColumn('uid', 'string', [
  970. 'notnull' => true,
  971. 'length' => 64,
  972. 'default' => '',
  973. ]);
  974. $table->addColumn('data', 'text', [
  975. 'notnull' => true,
  976. 'default' => '',
  977. ]);
  978. $table->setPrimaryKey(['uid']);
  979. }
  980. return $schema;
  981. }
  982. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  983. /** @var ISchemaWrapper $schema */
  984. $schema = $schemaClosure();
  985. if (!$schema->hasTable('dav_properties')) {
  986. return;
  987. }
  988. $query = $this->connection->getQueryBuilder();
  989. $query->select('*')
  990. ->from('dav_properties');
  991. $insert = $this->connection->getQueryBuilder();
  992. $insert->insert('properties')
  993. ->setValue('propertypath', $insert->createParameter('propertypath'))
  994. ->setValue('propertyname', $insert->createParameter('propertyname'))
  995. ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
  996. ->setValue('userid', $insert->createParameter('userid'));
  997. $result = $query->execute();
  998. while ($row = $result->fetch()) {
  999. preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
  1000. $insert->setParameter('propertypath', (string) $row['propertypath'])
  1001. ->setParameter('propertyname', (string) $row['propertyname'])
  1002. ->setParameter('propertyvalue', (string) $row['propertyvalue'])
  1003. ->setParameter('userid', ($match[2] ?? ''));
  1004. $insert->execute();
  1005. }
  1006. }
  1007. }