Version13000Date20170718121200.php 28 KB

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