1
0

Version13000Date20170718121200.php 24 KB

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