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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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', Type::BIGINT, [
  171. 'notnull' => true,
  172. 'length' => 20,
  173. 'default' => 0,
  174. ]);
  175. $table->addColumn('storage_mtime', Type::BIGINT, [
  176. 'notnull' => true,
  177. 'length' => 20,
  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. $table->addIndex(['mtime'], 'fs_mtime');
  210. }
  211. if (!$schema->hasTable('group_user')) {
  212. $table = $schema->createTable('group_user');
  213. $table->addColumn('gid', 'string', [
  214. 'notnull' => true,
  215. 'length' => 64,
  216. 'default' => '',
  217. ]);
  218. $table->addColumn('uid', 'string', [
  219. 'notnull' => true,
  220. 'length' => 64,
  221. 'default' => '',
  222. ]);
  223. $table->setPrimaryKey(['gid', 'uid']);
  224. $table->addIndex(['uid'], 'gu_uid_index');
  225. }
  226. if (!$schema->hasTable('group_admin')) {
  227. $table = $schema->createTable('group_admin');
  228. $table->addColumn('gid', 'string', [
  229. 'notnull' => true,
  230. 'length' => 64,
  231. 'default' => '',
  232. ]);
  233. $table->addColumn('uid', 'string', [
  234. 'notnull' => true,
  235. 'length' => 64,
  236. 'default' => '',
  237. ]);
  238. $table->setPrimaryKey(['gid', 'uid']);
  239. $table->addIndex(['uid'], 'group_admin_uid');
  240. }
  241. if (!$schema->hasTable('groups')) {
  242. $table = $schema->createTable('groups');
  243. $table->addColumn('gid', 'string', [
  244. 'notnull' => true,
  245. 'length' => 64,
  246. 'default' => '',
  247. ]);
  248. $table->setPrimaryKey(['gid']);
  249. }
  250. if (!$schema->hasTable('preferences')) {
  251. $table = $schema->createTable('preferences');
  252. $table->addColumn('userid', 'string', [
  253. 'notnull' => true,
  254. 'length' => 64,
  255. 'default' => '',
  256. ]);
  257. $table->addColumn('appid', 'string', [
  258. 'notnull' => true,
  259. 'length' => 32,
  260. 'default' => '',
  261. ]);
  262. $table->addColumn('configkey', 'string', [
  263. 'notnull' => true,
  264. 'length' => 64,
  265. 'default' => '',
  266. ]);
  267. $table->addColumn('configvalue', 'text', [
  268. 'notnull' => false,
  269. ]);
  270. $table->setPrimaryKey(['userid', 'appid', 'configkey']);
  271. }
  272. if (!$schema->hasTable('properties')) {
  273. $table = $schema->createTable('properties');
  274. $table->addColumn('id', 'integer', [
  275. 'autoincrement' => true,
  276. 'notnull' => true,
  277. 'length' => 4,
  278. ]);
  279. $table->addColumn('userid', 'string', [
  280. 'notnull' => true,
  281. 'length' => 64,
  282. 'default' => '',
  283. ]);
  284. $table->addColumn('propertypath', 'string', [
  285. 'notnull' => true,
  286. 'length' => 255,
  287. 'default' => '',
  288. ]);
  289. $table->addColumn('propertyname', 'string', [
  290. 'notnull' => true,
  291. 'length' => 255,
  292. 'default' => '',
  293. ]);
  294. $table->addColumn('propertyvalue', 'text', [
  295. 'notnull' => true,
  296. ]);
  297. $table->setPrimaryKey(['id']);
  298. $table->addIndex(['userid'], 'property_index');
  299. }
  300. if (!$schema->hasTable('share')) {
  301. $table = $schema->createTable('share');
  302. $table->addColumn('id', 'integer', [
  303. 'autoincrement' => true,
  304. 'notnull' => true,
  305. 'length' => 4,
  306. ]);
  307. $table->addColumn('share_type', 'smallint', [
  308. 'notnull' => true,
  309. 'length' => 1,
  310. 'default' => 0,
  311. ]);
  312. $table->addColumn('share_with', 'string', [
  313. 'notnull' => false,
  314. 'length' => 255,
  315. ]);
  316. $table->addColumn('password', 'string', [
  317. 'notnull' => false,
  318. 'length' => 255,
  319. ]);
  320. $table->addColumn('uid_owner', 'string', [
  321. 'notnull' => true,
  322. 'length' => 64,
  323. 'default' => '',
  324. ]);
  325. $table->addColumn('uid_initiator', 'string', [
  326. 'notnull' => false,
  327. 'length' => 64,
  328. ]);
  329. $table->addColumn('parent', 'integer', [
  330. 'notnull' => false,
  331. 'length' => 4,
  332. ]);
  333. $table->addColumn('item_type', 'string', [
  334. 'notnull' => true,
  335. 'length' => 64,
  336. 'default' => '',
  337. ]);
  338. $table->addColumn('item_source', 'string', [
  339. 'notnull' => false,
  340. 'length' => 255,
  341. ]);
  342. $table->addColumn('item_target', 'string', [
  343. 'notnull' => false,
  344. 'length' => 255,
  345. ]);
  346. $table->addColumn('file_source', 'integer', [
  347. 'notnull' => false,
  348. 'length' => 4,
  349. ]);
  350. $table->addColumn('file_target', 'string', [
  351. 'notnull' => false,
  352. 'length' => 512,
  353. ]);
  354. $table->addColumn('permissions', 'smallint', [
  355. 'notnull' => true,
  356. 'length' => 1,
  357. 'default' => 0,
  358. ]);
  359. $table->addColumn('stime', 'bigint', [
  360. 'notnull' => true,
  361. 'length' => 8,
  362. 'default' => 0,
  363. ]);
  364. $table->addColumn('accepted', 'smallint', [
  365. 'notnull' => true,
  366. 'length' => 1,
  367. 'default' => 0,
  368. ]);
  369. $table->addColumn('expiration', 'datetime', [
  370. 'notnull' => false,
  371. ]);
  372. $table->addColumn('token', 'string', [
  373. 'notnull' => false,
  374. 'length' => 32,
  375. ]);
  376. $table->addColumn('mail_send', 'smallint', [
  377. 'notnull' => true,
  378. 'length' => 1,
  379. 'default' => 0,
  380. ]);
  381. $table->addColumn('share_name', 'string', [
  382. 'notnull' => false,
  383. 'length' => 64,
  384. ]);
  385. $table->setPrimaryKey(['id']);
  386. $table->addIndex(['item_type', 'share_type'], 'item_share_type_index');
  387. $table->addIndex(['file_source'], 'file_source_index');
  388. $table->addIndex(['token'], 'token_index');
  389. $table->addIndex(['share_with'], 'share_with_index');
  390. $table->addIndex(['parent'], 'parent_index');
  391. $table->addIndex(['uid_owner'], 'owner_index');
  392. $table->addIndex(['uid_initiator'], 'initiator_index');
  393. }
  394. if (!$schema->hasTable('jobs')) {
  395. $table = $schema->createTable('jobs');
  396. $table->addColumn('id', 'integer', [
  397. 'autoincrement' => true,
  398. 'notnull' => true,
  399. 'length' => 4,
  400. 'unsigned' => true,
  401. ]);
  402. $table->addColumn('class', 'string', [
  403. 'notnull' => true,
  404. 'length' => 255,
  405. 'default' => '',
  406. ]);
  407. $table->addColumn('argument', 'string', [
  408. 'notnull' => true,
  409. 'length' => 4000,
  410. 'default' => '',
  411. ]);
  412. $table->addColumn('last_run', 'integer', [
  413. 'notnull' => false,
  414. 'default' => 0,
  415. ]);
  416. $table->addColumn('last_checked', 'integer', [
  417. 'notnull' => false,
  418. 'default' => 0,
  419. ]);
  420. $table->addColumn('reserved_at', 'integer', [
  421. 'notnull' => false,
  422. 'default' => 0,
  423. ]);
  424. $table->addColumn('execution_duration', 'integer', [
  425. 'notnull' => true,
  426. 'default' => 0,
  427. ]);
  428. $table->setPrimaryKey(['id']);
  429. $table->addIndex(['class'], 'job_class_index');
  430. }
  431. if (!$schema->hasTable('users')) {
  432. $table = $schema->createTable('users');
  433. $table->addColumn('uid', 'string', [
  434. 'notnull' => true,
  435. 'length' => 64,
  436. 'default' => '',
  437. ]);
  438. $table->addColumn('displayname', 'string', [
  439. 'notnull' => false,
  440. 'length' => 64,
  441. ]);
  442. $table->addColumn('password', 'string', [
  443. 'notnull' => true,
  444. 'length' => 255,
  445. 'default' => '',
  446. ]);
  447. $table->setPrimaryKey(['uid']);
  448. }
  449. if (!$schema->hasTable('authtoken')) {
  450. $table = $schema->createTable('authtoken');
  451. $table->addColumn('id', 'integer', [
  452. 'autoincrement' => true,
  453. 'notnull' => true,
  454. 'length' => 4,
  455. 'unsigned' => true,
  456. ]);
  457. $table->addColumn('uid', 'string', [
  458. 'notnull' => true,
  459. 'length' => 64,
  460. 'default' => '',
  461. ]);
  462. $table->addColumn('login_name', 'string', [
  463. 'notnull' => true,
  464. 'length' => 64,
  465. 'default' => '',
  466. ]);
  467. $table->addColumn('password', 'text', [
  468. 'notnull' => false,
  469. ]);
  470. $table->addColumn('name', 'text', [
  471. 'notnull' => true,
  472. 'default' => '',
  473. ]);
  474. $table->addColumn('token', 'string', [
  475. 'notnull' => true,
  476. 'length' => 200,
  477. 'default' => '',
  478. ]);
  479. $table->addColumn('type', 'smallint', [
  480. 'notnull' => true,
  481. 'length' => 2,
  482. 'default' => 0,
  483. 'unsigned' => true,
  484. ]);
  485. $table->addColumn('remember', 'smallint', [
  486. 'notnull' => true,
  487. 'length' => 1,
  488. 'default' => 0,
  489. 'unsigned' => true,
  490. ]);
  491. $table->addColumn('last_activity', 'integer', [
  492. 'notnull' => true,
  493. 'length' => 4,
  494. 'default' => 0,
  495. 'unsigned' => true,
  496. ]);
  497. $table->addColumn('last_check', 'integer', [
  498. 'notnull' => true,
  499. 'length' => 4,
  500. 'default' => 0,
  501. 'unsigned' => true,
  502. ]);
  503. $table->addColumn('scope', 'text', [
  504. 'notnull' => false,
  505. ]);
  506. $table->setPrimaryKey(['id']);
  507. $table->addUniqueIndex(['token'], 'authtoken_token_index');
  508. $table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
  509. }
  510. if (!$schema->hasTable('bruteforce_attempts')) {
  511. $table = $schema->createTable('bruteforce_attempts');
  512. $table->addColumn('id', 'integer', [
  513. 'autoincrement' => true,
  514. 'notnull' => true,
  515. 'length' => 4,
  516. 'unsigned' => true,
  517. ]);
  518. $table->addColumn('action', 'string', [
  519. 'notnull' => true,
  520. 'length' => 64,
  521. 'default' => '',
  522. ]);
  523. $table->addColumn('occurred', 'integer', [
  524. 'notnull' => true,
  525. 'length' => 4,
  526. 'default' => 0,
  527. 'unsigned' => true,
  528. ]);
  529. $table->addColumn('ip', 'string', [
  530. 'notnull' => true,
  531. 'length' => 255,
  532. 'default' => '',
  533. ]);
  534. $table->addColumn('subnet', 'string', [
  535. 'notnull' => true,
  536. 'length' => 255,
  537. 'default' => '',
  538. ]);
  539. $table->addColumn('metadata', 'string', [
  540. 'notnull' => true,
  541. 'length' => 255,
  542. 'default' => '',
  543. ]);
  544. $table->setPrimaryKey(['id']);
  545. $table->addIndex(['ip'], 'bruteforce_attempts_ip');
  546. $table->addIndex(['subnet'], 'bruteforce_attempts_subnet');
  547. }
  548. if (!$schema->hasTable('vcategory')) {
  549. $table = $schema->createTable('vcategory');
  550. $table->addColumn('id', 'integer', [
  551. 'autoincrement' => true,
  552. 'notnull' => true,
  553. 'length' => 4,
  554. 'unsigned' => true,
  555. ]);
  556. $table->addColumn('uid', 'string', [
  557. 'notnull' => true,
  558. 'length' => 64,
  559. 'default' => '',
  560. ]);
  561. $table->addColumn('type', 'string', [
  562. 'notnull' => true,
  563. 'length' => 64,
  564. 'default' => '',
  565. ]);
  566. $table->addColumn('category', 'string', [
  567. 'notnull' => true,
  568. 'length' => 255,
  569. 'default' => '',
  570. ]);
  571. $table->setPrimaryKey(['id']);
  572. $table->addIndex(['uid'], 'uid_index');
  573. $table->addIndex(['type'], 'type_index');
  574. $table->addIndex(['category'], 'category_index');
  575. }
  576. if (!$schema->hasTable('vcategory_to_object')) {
  577. $table = $schema->createTable('vcategory_to_object');
  578. $table->addColumn('objid', 'integer', [
  579. 'notnull' => true,
  580. 'length' => 4,
  581. 'default' => 0,
  582. 'unsigned' => true,
  583. ]);
  584. $table->addColumn('categoryid', 'integer', [
  585. 'notnull' => true,
  586. 'length' => 4,
  587. 'default' => 0,
  588. 'unsigned' => true,
  589. ]);
  590. $table->addColumn('type', 'string', [
  591. 'notnull' => true,
  592. 'length' => 64,
  593. 'default' => '',
  594. ]);
  595. $table->setPrimaryKey(['categoryid', 'objid', 'type']);
  596. $table->addIndex(['objid', 'type'], 'vcategory_objectd_index');
  597. }
  598. if (!$schema->hasTable('systemtag')) {
  599. $table = $schema->createTable('systemtag');
  600. $table->addColumn('id', 'integer', [
  601. 'autoincrement' => true,
  602. 'notnull' => true,
  603. 'length' => 4,
  604. 'unsigned' => true,
  605. ]);
  606. $table->addColumn('name', 'string', [
  607. 'notnull' => true,
  608. 'length' => 64,
  609. 'default' => '',
  610. ]);
  611. $table->addColumn('visibility', 'smallint', [
  612. 'notnull' => true,
  613. 'length' => 1,
  614. 'default' => 1,
  615. ]);
  616. $table->addColumn('editable', 'smallint', [
  617. 'notnull' => true,
  618. 'length' => 1,
  619. 'default' => 1,
  620. ]);
  621. $table->setPrimaryKey(['id']);
  622. $table->addUniqueIndex(['name', 'visibility', 'editable'], 'tag_ident');
  623. }
  624. if (!$schema->hasTable('systemtag_object_mapping')) {
  625. $table = $schema->createTable('systemtag_object_mapping');
  626. $table->addColumn('objectid', 'string', [
  627. 'notnull' => true,
  628. 'length' => 64,
  629. 'default' => '',
  630. ]);
  631. $table->addColumn('objecttype', 'string', [
  632. 'notnull' => true,
  633. 'length' => 64,
  634. 'default' => '',
  635. ]);
  636. $table->addColumn('systemtagid', 'integer', [
  637. 'notnull' => true,
  638. 'length' => 4,
  639. 'default' => 0,
  640. 'unsigned' => true,
  641. ]);
  642. $table->addUniqueIndex(['objecttype', 'objectid', 'systemtagid'], 'mapping');
  643. }
  644. if (!$schema->hasTable('systemtag_group')) {
  645. $table = $schema->createTable('systemtag_group');
  646. $table->addColumn('systemtagid', 'integer', [
  647. 'notnull' => true,
  648. 'length' => 4,
  649. 'default' => 0,
  650. 'unsigned' => true,
  651. ]);
  652. $table->addColumn('gid', 'string', [
  653. 'notnull' => true,
  654. ]);
  655. $table->setPrimaryKey(['gid', 'systemtagid']);
  656. }
  657. if (!$schema->hasTable('file_locks')) {
  658. $table = $schema->createTable('file_locks');
  659. $table->addColumn('id', 'integer', [
  660. 'autoincrement' => true,
  661. 'notnull' => true,
  662. 'length' => 4,
  663. 'unsigned' => true,
  664. ]);
  665. $table->addColumn('lock', 'integer', [
  666. 'notnull' => true,
  667. 'length' => 4,
  668. 'default' => 0,
  669. ]);
  670. $table->addColumn('key', 'string', [
  671. 'notnull' => true,
  672. 'length' => 64,
  673. ]);
  674. $table->addColumn('ttl', 'integer', [
  675. 'notnull' => true,
  676. 'length' => 4,
  677. 'default' => -1,
  678. ]);
  679. $table->setPrimaryKey(['id']);
  680. $table->addUniqueIndex(['key'], 'lock_key_index');
  681. $table->addIndex(['ttl'], 'lock_ttl_index');
  682. }
  683. if (!$schema->hasTable('comments')) {
  684. $table = $schema->createTable('comments');
  685. $table->addColumn('id', 'integer', [
  686. 'autoincrement' => true,
  687. 'notnull' => true,
  688. 'length' => 4,
  689. 'unsigned' => true,
  690. ]);
  691. $table->addColumn('parent_id', 'integer', [
  692. 'notnull' => true,
  693. 'length' => 4,
  694. 'default' => 0,
  695. 'unsigned' => true,
  696. ]);
  697. $table->addColumn('topmost_parent_id', 'integer', [
  698. 'notnull' => true,
  699. 'length' => 4,
  700. 'default' => 0,
  701. 'unsigned' => true,
  702. ]);
  703. $table->addColumn('children_count', 'integer', [
  704. 'notnull' => true,
  705. 'length' => 4,
  706. 'default' => 0,
  707. 'unsigned' => true,
  708. ]);
  709. $table->addColumn('actor_type', 'string', [
  710. 'notnull' => true,
  711. 'length' => 64,
  712. 'default' => '',
  713. ]);
  714. $table->addColumn('actor_id', 'string', [
  715. 'notnull' => true,
  716. 'length' => 64,
  717. 'default' => '',
  718. ]);
  719. $table->addColumn('message', 'text', [
  720. 'notnull' => false,
  721. ]);
  722. $table->addColumn('verb', 'string', [
  723. 'notnull' => false,
  724. 'length' => 64,
  725. ]);
  726. $table->addColumn('creation_timestamp', 'datetime', [
  727. 'notnull' => false,
  728. ]);
  729. $table->addColumn('latest_child_timestamp', 'datetime', [
  730. 'notnull' => false,
  731. ]);
  732. $table->addColumn('object_type', 'string', [
  733. 'notnull' => true,
  734. 'length' => 64,
  735. 'default' => '',
  736. ]);
  737. $table->addColumn('object_id', 'string', [
  738. 'notnull' => true,
  739. 'length' => 64,
  740. 'default' => '',
  741. ]);
  742. $table->setPrimaryKey(['id']);
  743. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  744. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  745. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  746. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  747. }
  748. if (!$schema->hasTable('comments_read_markers')) {
  749. $table = $schema->createTable('comments_read_markers');
  750. $table->addColumn('user_id', 'string', [
  751. 'notnull' => true,
  752. 'length' => 64,
  753. 'default' => '',
  754. ]);
  755. $table->addColumn('marker_datetime', 'datetime', [
  756. 'notnull' => false,
  757. ]);
  758. $table->addColumn('object_type', 'string', [
  759. 'notnull' => true,
  760. 'length' => 64,
  761. 'default' => '',
  762. ]);
  763. $table->addColumn('object_id', 'string', [
  764. 'notnull' => true,
  765. 'length' => 64,
  766. 'default' => '',
  767. ]);
  768. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  769. $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  770. }
  771. if (!$schema->hasTable('credentials')) {
  772. $table = $schema->createTable('credentials');
  773. $table->addColumn('user', 'string', [
  774. 'notnull' => true,
  775. 'length' => 64,
  776. ]);
  777. $table->addColumn('identifier', 'string', [
  778. 'notnull' => true,
  779. 'length' => 64,
  780. ]);
  781. $table->addColumn('credentials', 'text', [
  782. 'notnull' => false,
  783. ]);
  784. $table->setPrimaryKey(['user', 'identifier']);
  785. $table->addIndex(['user'], 'credentials_user');
  786. }
  787. if (!$schema->hasTable('admin_sections')) {
  788. $table = $schema->createTable('admin_sections');
  789. $table->addColumn('id', 'string', [
  790. 'notnull' => true,
  791. 'length' => 64,
  792. ]);
  793. $table->addColumn('class', 'string', [
  794. 'notnull' => true,
  795. 'length' => 255,
  796. 'default' => '',
  797. ]);
  798. $table->addColumn('priority', 'smallint', [
  799. 'notnull' => true,
  800. 'length' => 1,
  801. 'default' => 0,
  802. ]);
  803. $table->setPrimaryKey(['id']);
  804. $table->addUniqueIndex(['class'], 'admin_sections_class');
  805. }
  806. if (!$schema->hasTable('admin_settings')) {
  807. $table = $schema->createTable('admin_settings');
  808. $table->addColumn('id', 'integer', [
  809. 'autoincrement' => true,
  810. 'notnull' => true,
  811. 'length' => 4,
  812. ]);
  813. $table->addColumn('class', 'string', [
  814. 'notnull' => true,
  815. 'length' => 255,
  816. 'default' => '',
  817. ]);
  818. $table->addColumn('section', 'string', [
  819. 'notnull' => false,
  820. 'length' => 64,
  821. ]);
  822. $table->addColumn('priority', 'smallint', [
  823. 'notnull' => true,
  824. 'length' => 1,
  825. 'default' => 0,
  826. ]);
  827. $table->setPrimaryKey(['id']);
  828. $table->addUniqueIndex(['class'], 'admin_settings_class');
  829. $table->addIndex(['section'], 'admin_settings_section');
  830. }
  831. if (!$schema->hasTable('personal_sections')) {
  832. $table = $schema->createTable('personal_sections');
  833. $table->addColumn('id', 'string', [
  834. 'notnull' => true,
  835. 'length' => 64,
  836. ]);
  837. $table->addColumn('class', 'string', [
  838. 'notnull' => true,
  839. 'length' => 255,
  840. 'default' => '',
  841. ]);
  842. $table->addColumn('priority', 'smallint', [
  843. 'notnull' => true,
  844. 'length' => 1,
  845. 'default' => 0,
  846. ]);
  847. $table->setPrimaryKey(['id']);
  848. $table->addUniqueIndex(['class'], 'personal_sections_class');
  849. }
  850. if (!$schema->hasTable('personal_settings')) {
  851. $table = $schema->createTable('personal_settings');
  852. $table->addColumn('id', 'integer', [
  853. 'autoincrement' => true,
  854. 'notnull' => true,
  855. 'length' => 4,
  856. ]);
  857. $table->addColumn('class', 'string', [
  858. 'notnull' => true,
  859. 'length' => 255,
  860. 'default' => '',
  861. ]);
  862. $table->addColumn('section', 'string', [
  863. 'notnull' => false,
  864. 'length' => 64,
  865. ]);
  866. $table->addColumn('priority', 'smallint', [
  867. 'notnull' => true,
  868. 'length' => 1,
  869. 'default' => 0,
  870. ]);
  871. $table->setPrimaryKey(['id']);
  872. $table->addUniqueIndex(['class'], 'personal_settings_class');
  873. $table->addIndex(['section'], 'personal_settings_section');
  874. }
  875. if (!$schema->hasTable('accounts')) {
  876. $table = $schema->createTable('accounts');
  877. $table->addColumn('uid', 'string', [
  878. 'notnull' => true,
  879. 'length' => 64,
  880. 'default' => '',
  881. ]);
  882. $table->addColumn('data', 'text', [
  883. 'notnull' => true,
  884. 'default' => '',
  885. ]);
  886. $table->setPrimaryKey(['uid']);
  887. }
  888. return $schema;
  889. }
  890. }