Version13000Date20170718121200.php 24 KB

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