1
0

Version13000Date20170718121200.php 25 KB

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