Version13000Date20170718121200.php 29 KB

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