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 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
  654. }
  655. if (!$schema->hasTable('systemtag_group')) {
  656. $table = $schema->createTable('systemtag_group');
  657. $table->addColumn('systemtagid', 'integer', [
  658. 'notnull' => true,
  659. 'length' => 4,
  660. 'default' => 0,
  661. 'unsigned' => true,
  662. ]);
  663. $table->addColumn('gid', 'string', [
  664. 'notnull' => true,
  665. ]);
  666. $table->setPrimaryKey(['gid', 'systemtagid']);
  667. }
  668. if (!$schema->hasTable('file_locks')) {
  669. $table = $schema->createTable('file_locks');
  670. $table->addColumn('id', 'integer', [
  671. 'autoincrement' => true,
  672. 'notnull' => true,
  673. 'length' => 4,
  674. 'unsigned' => true,
  675. ]);
  676. $table->addColumn('lock', 'integer', [
  677. 'notnull' => true,
  678. 'length' => 4,
  679. 'default' => 0,
  680. ]);
  681. $table->addColumn('key', 'string', [
  682. 'notnull' => true,
  683. 'length' => 64,
  684. ]);
  685. $table->addColumn('ttl', 'integer', [
  686. 'notnull' => true,
  687. 'length' => 4,
  688. 'default' => -1,
  689. ]);
  690. $table->setPrimaryKey(['id']);
  691. $table->addUniqueIndex(['key'], 'lock_key_index');
  692. $table->addIndex(['ttl'], 'lock_ttl_index');
  693. }
  694. if (!$schema->hasTable('comments')) {
  695. $table = $schema->createTable('comments');
  696. $table->addColumn('id', 'integer', [
  697. 'autoincrement' => true,
  698. 'notnull' => true,
  699. 'length' => 4,
  700. 'unsigned' => true,
  701. ]);
  702. $table->addColumn('parent_id', 'integer', [
  703. 'notnull' => true,
  704. 'length' => 4,
  705. 'default' => 0,
  706. 'unsigned' => true,
  707. ]);
  708. $table->addColumn('topmost_parent_id', 'integer', [
  709. 'notnull' => true,
  710. 'length' => 4,
  711. 'default' => 0,
  712. 'unsigned' => true,
  713. ]);
  714. $table->addColumn('children_count', 'integer', [
  715. 'notnull' => true,
  716. 'length' => 4,
  717. 'default' => 0,
  718. 'unsigned' => true,
  719. ]);
  720. $table->addColumn('actor_type', 'string', [
  721. 'notnull' => true,
  722. 'length' => 64,
  723. 'default' => '',
  724. ]);
  725. $table->addColumn('actor_id', 'string', [
  726. 'notnull' => true,
  727. 'length' => 64,
  728. 'default' => '',
  729. ]);
  730. $table->addColumn('message', 'text', [
  731. 'notnull' => false,
  732. ]);
  733. $table->addColumn('verb', 'string', [
  734. 'notnull' => false,
  735. 'length' => 64,
  736. ]);
  737. $table->addColumn('creation_timestamp', 'datetime', [
  738. 'notnull' => false,
  739. ]);
  740. $table->addColumn('latest_child_timestamp', 'datetime', [
  741. 'notnull' => false,
  742. ]);
  743. $table->addColumn('object_type', 'string', [
  744. 'notnull' => true,
  745. 'length' => 64,
  746. 'default' => '',
  747. ]);
  748. $table->addColumn('object_id', 'string', [
  749. 'notnull' => true,
  750. 'length' => 64,
  751. 'default' => '',
  752. ]);
  753. $table->addColumn('reference_id', 'string', [
  754. 'notnull' => false,
  755. 'length' => 64,
  756. ]);
  757. $table->setPrimaryKey(['id']);
  758. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  759. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  760. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  761. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  762. }
  763. if (!$schema->hasTable('comments_read_markers')) {
  764. $table = $schema->createTable('comments_read_markers');
  765. $table->addColumn('user_id', 'string', [
  766. 'notnull' => true,
  767. 'length' => 64,
  768. 'default' => '',
  769. ]);
  770. $table->addColumn('marker_datetime', 'datetime', [
  771. 'notnull' => false,
  772. ]);
  773. $table->addColumn('object_type', 'string', [
  774. 'notnull' => true,
  775. 'length' => 64,
  776. 'default' => '',
  777. ]);
  778. $table->addColumn('object_id', 'string', [
  779. 'notnull' => true,
  780. 'length' => 64,
  781. 'default' => '',
  782. ]);
  783. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  784. $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  785. }
  786. if (!$schema->hasTable('credentials')) {
  787. $table = $schema->createTable('credentials');
  788. $table->addColumn('user', 'string', [
  789. 'notnull' => true,
  790. 'length' => 64,
  791. ]);
  792. $table->addColumn('identifier', 'string', [
  793. 'notnull' => true,
  794. 'length' => 64,
  795. ]);
  796. $table->addColumn('credentials', 'text', [
  797. 'notnull' => false,
  798. ]);
  799. $table->setPrimaryKey(['user', 'identifier']);
  800. $table->addIndex(['user'], 'credentials_user');
  801. }
  802. if (!$schema->hasTable('admin_sections')) {
  803. $table = $schema->createTable('admin_sections');
  804. $table->addColumn('id', 'string', [
  805. 'notnull' => true,
  806. 'length' => 64,
  807. ]);
  808. $table->addColumn('class', 'string', [
  809. 'notnull' => true,
  810. 'length' => 255,
  811. 'default' => '',
  812. ]);
  813. $table->addColumn('priority', 'smallint', [
  814. 'notnull' => true,
  815. 'length' => 1,
  816. 'default' => 0,
  817. ]);
  818. $table->setPrimaryKey(['id']);
  819. $table->addUniqueIndex(['class'], 'admin_sections_class');
  820. }
  821. if (!$schema->hasTable('admin_settings')) {
  822. $table = $schema->createTable('admin_settings');
  823. $table->addColumn('id', 'integer', [
  824. 'autoincrement' => true,
  825. 'notnull' => true,
  826. 'length' => 4,
  827. ]);
  828. $table->addColumn('class', 'string', [
  829. 'notnull' => true,
  830. 'length' => 255,
  831. 'default' => '',
  832. ]);
  833. $table->addColumn('section', 'string', [
  834. 'notnull' => false,
  835. 'length' => 64,
  836. ]);
  837. $table->addColumn('priority', 'smallint', [
  838. 'notnull' => true,
  839. 'length' => 1,
  840. 'default' => 0,
  841. ]);
  842. $table->setPrimaryKey(['id']);
  843. $table->addUniqueIndex(['class'], 'admin_settings_class');
  844. $table->addIndex(['section'], 'admin_settings_section');
  845. }
  846. if (!$schema->hasTable('personal_sections')) {
  847. $table = $schema->createTable('personal_sections');
  848. $table->addColumn('id', 'string', [
  849. 'notnull' => true,
  850. 'length' => 64,
  851. ]);
  852. $table->addColumn('class', 'string', [
  853. 'notnull' => true,
  854. 'length' => 255,
  855. 'default' => '',
  856. ]);
  857. $table->addColumn('priority', 'smallint', [
  858. 'notnull' => true,
  859. 'length' => 1,
  860. 'default' => 0,
  861. ]);
  862. $table->setPrimaryKey(['id']);
  863. $table->addUniqueIndex(['class'], 'personal_sections_class');
  864. }
  865. if (!$schema->hasTable('personal_settings')) {
  866. $table = $schema->createTable('personal_settings');
  867. $table->addColumn('id', 'integer', [
  868. 'autoincrement' => true,
  869. 'notnull' => true,
  870. 'length' => 4,
  871. ]);
  872. $table->addColumn('class', 'string', [
  873. 'notnull' => true,
  874. 'length' => 255,
  875. 'default' => '',
  876. ]);
  877. $table->addColumn('section', 'string', [
  878. 'notnull' => false,
  879. 'length' => 64,
  880. ]);
  881. $table->addColumn('priority', 'smallint', [
  882. 'notnull' => true,
  883. 'length' => 1,
  884. 'default' => 0,
  885. ]);
  886. $table->setPrimaryKey(['id']);
  887. $table->addUniqueIndex(['class'], 'personal_settings_class');
  888. $table->addIndex(['section'], 'personal_settings_section');
  889. }
  890. if (!$schema->hasTable('accounts')) {
  891. $table = $schema->createTable('accounts');
  892. $table->addColumn('uid', 'string', [
  893. 'notnull' => true,
  894. 'length' => 64,
  895. 'default' => '',
  896. ]);
  897. $table->addColumn('data', 'text', [
  898. 'notnull' => true,
  899. 'default' => '',
  900. ]);
  901. $table->setPrimaryKey(['uid']);
  902. }
  903. return $schema;
  904. }
  905. }