Version13000Date20170718121200.php 25 KB

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