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\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. $table->addIndex(['systemtagid', 'objecttype'], 'systag_by_tagid');
  732. }
  733. if (!$schema->hasTable('systemtag_group')) {
  734. $table = $schema->createTable('systemtag_group');
  735. $table->addColumn('systemtagid', 'integer', [
  736. 'notnull' => true,
  737. 'length' => 4,
  738. 'default' => 0,
  739. 'unsigned' => true,
  740. ]);
  741. $table->addColumn('gid', 'string', [
  742. 'notnull' => true,
  743. ]);
  744. $table->setPrimaryKey(['gid', 'systemtagid']);
  745. }
  746. if (!$schema->hasTable('file_locks')) {
  747. $table = $schema->createTable('file_locks');
  748. $table->addColumn('id', 'integer', [
  749. 'autoincrement' => true,
  750. 'notnull' => true,
  751. 'length' => 4,
  752. 'unsigned' => true,
  753. ]);
  754. $table->addColumn('lock', 'integer', [
  755. 'notnull' => true,
  756. 'length' => 4,
  757. 'default' => 0,
  758. ]);
  759. $table->addColumn('key', 'string', [
  760. 'notnull' => true,
  761. 'length' => 64,
  762. ]);
  763. $table->addColumn('ttl', 'integer', [
  764. 'notnull' => true,
  765. 'length' => 4,
  766. 'default' => -1,
  767. ]);
  768. $table->setPrimaryKey(['id']);
  769. $table->addUniqueIndex(['key'], 'lock_key_index');
  770. $table->addIndex(['ttl'], 'lock_ttl_index');
  771. }
  772. if (!$schema->hasTable('comments')) {
  773. $table = $schema->createTable('comments');
  774. $table->addColumn('id', 'integer', [
  775. 'autoincrement' => true,
  776. 'notnull' => true,
  777. 'length' => 4,
  778. 'unsigned' => true,
  779. ]);
  780. $table->addColumn('parent_id', 'integer', [
  781. 'notnull' => true,
  782. 'length' => 4,
  783. 'default' => 0,
  784. 'unsigned' => true,
  785. ]);
  786. $table->addColumn('topmost_parent_id', 'integer', [
  787. 'notnull' => true,
  788. 'length' => 4,
  789. 'default' => 0,
  790. 'unsigned' => true,
  791. ]);
  792. $table->addColumn('children_count', 'integer', [
  793. 'notnull' => true,
  794. 'length' => 4,
  795. 'default' => 0,
  796. 'unsigned' => true,
  797. ]);
  798. $table->addColumn('actor_type', 'string', [
  799. 'notnull' => true,
  800. 'length' => 64,
  801. 'default' => '',
  802. ]);
  803. $table->addColumn('actor_id', 'string', [
  804. 'notnull' => true,
  805. 'length' => 64,
  806. 'default' => '',
  807. ]);
  808. $table->addColumn('message', 'text', [
  809. 'notnull' => false,
  810. ]);
  811. $table->addColumn('verb', 'string', [
  812. 'notnull' => false,
  813. 'length' => 64,
  814. ]);
  815. $table->addColumn('creation_timestamp', 'datetime', [
  816. 'notnull' => false,
  817. ]);
  818. $table->addColumn('latest_child_timestamp', 'datetime', [
  819. 'notnull' => false,
  820. ]);
  821. $table->addColumn('object_type', 'string', [
  822. 'notnull' => true,
  823. 'length' => 64,
  824. 'default' => '',
  825. ]);
  826. $table->addColumn('object_id', 'string', [
  827. 'notnull' => true,
  828. 'length' => 64,
  829. 'default' => '',
  830. ]);
  831. $table->addColumn('reference_id', 'string', [
  832. 'notnull' => false,
  833. 'length' => 64,
  834. ]);
  835. $table->setPrimaryKey(['id']);
  836. $table->addIndex(['parent_id'], 'comments_parent_id_index');
  837. $table->addIndex(['topmost_parent_id'], 'comments_topmost_parent_id_idx');
  838. $table->addIndex(['object_type', 'object_id', 'creation_timestamp'], 'comments_object_index');
  839. $table->addIndex(['actor_type', 'actor_id'], 'comments_actor_index');
  840. }
  841. if (!$schema->hasTable('comments_read_markers')) {
  842. $table = $schema->createTable('comments_read_markers');
  843. $table->addColumn('user_id', 'string', [
  844. 'notnull' => true,
  845. 'length' => 64,
  846. 'default' => '',
  847. ]);
  848. $table->addColumn('marker_datetime', 'datetime', [
  849. 'notnull' => false,
  850. ]);
  851. $table->addColumn('object_type', 'string', [
  852. 'notnull' => true,
  853. 'length' => 64,
  854. 'default' => '',
  855. ]);
  856. $table->addColumn('object_id', 'string', [
  857. 'notnull' => true,
  858. 'length' => 64,
  859. 'default' => '',
  860. ]);
  861. $table->addIndex(['object_type', 'object_id'], 'comments_marker_object_index');
  862. $table->setPrimaryKey(['user_id', 'object_type', 'object_id'], 'crm_pk');
  863. // $table->addUniqueIndex(['user_id', 'object_type', 'object_id'], 'comments_marker_index');
  864. }
  865. // if (!$schema->hasTable('credentials')) {
  866. // $table = $schema->createTable('credentials');
  867. // $table->addColumn('user', 'string', [
  868. // 'notnull' => false,
  869. // 'length' => 64,
  870. // ]);
  871. // $table->addColumn('identifier', 'string', [
  872. // 'notnull' => true,
  873. // 'length' => 64,
  874. // ]);
  875. // $table->addColumn('credentials', 'text', [
  876. // 'notnull' => false,
  877. // ]);
  878. // $table->setPrimaryKey(['user', 'identifier']);
  879. // $table->addIndex(['user'], 'credentials_user');
  880. // }
  881. if (!$schema->hasTable('admin_sections')) {
  882. $table = $schema->createTable('admin_sections');
  883. $table->addColumn('id', 'string', [
  884. 'notnull' => true,
  885. 'length' => 64,
  886. ]);
  887. $table->addColumn('class', 'string', [
  888. 'notnull' => true,
  889. 'length' => 255,
  890. 'default' => '',
  891. ]);
  892. $table->addColumn('priority', 'smallint', [
  893. 'notnull' => true,
  894. 'length' => 1,
  895. 'default' => 0,
  896. ]);
  897. $table->setPrimaryKey(['id']);
  898. $table->addUniqueIndex(['class'], 'admin_sections_class');
  899. }
  900. if (!$schema->hasTable('admin_settings')) {
  901. $table = $schema->createTable('admin_settings');
  902. $table->addColumn('id', 'integer', [
  903. 'autoincrement' => true,
  904. 'notnull' => true,
  905. 'length' => 4,
  906. ]);
  907. $table->addColumn('class', 'string', [
  908. 'notnull' => true,
  909. 'length' => 255,
  910. 'default' => '',
  911. ]);
  912. $table->addColumn('section', 'string', [
  913. 'notnull' => false,
  914. 'length' => 64,
  915. ]);
  916. $table->addColumn('priority', 'smallint', [
  917. 'notnull' => true,
  918. 'length' => 1,
  919. 'default' => 0,
  920. ]);
  921. $table->setPrimaryKey(['id']);
  922. $table->addUniqueIndex(['class'], 'admin_settings_class');
  923. $table->addIndex(['section'], 'admin_settings_section');
  924. }
  925. if (!$schema->hasTable('personal_sections')) {
  926. $table = $schema->createTable('personal_sections');
  927. $table->addColumn('id', 'string', [
  928. 'notnull' => true,
  929. 'length' => 64,
  930. ]);
  931. $table->addColumn('class', 'string', [
  932. 'notnull' => true,
  933. 'length' => 255,
  934. 'default' => '',
  935. ]);
  936. $table->addColumn('priority', 'smallint', [
  937. 'notnull' => true,
  938. 'length' => 1,
  939. 'default' => 0,
  940. ]);
  941. $table->setPrimaryKey(['id']);
  942. $table->addUniqueIndex(['class'], 'personal_sections_class');
  943. }
  944. if (!$schema->hasTable('personal_settings')) {
  945. $table = $schema->createTable('personal_settings');
  946. $table->addColumn('id', 'integer', [
  947. 'autoincrement' => true,
  948. 'notnull' => true,
  949. 'length' => 4,
  950. ]);
  951. $table->addColumn('class', 'string', [
  952. 'notnull' => true,
  953. 'length' => 255,
  954. 'default' => '',
  955. ]);
  956. $table->addColumn('section', 'string', [
  957. 'notnull' => false,
  958. 'length' => 64,
  959. ]);
  960. $table->addColumn('priority', 'smallint', [
  961. 'notnull' => true,
  962. 'length' => 1,
  963. 'default' => 0,
  964. ]);
  965. $table->setPrimaryKey(['id']);
  966. $table->addUniqueIndex(['class'], 'personal_settings_class');
  967. $table->addIndex(['section'], 'personal_settings_section');
  968. }
  969. if (!$schema->hasTable('accounts')) {
  970. $table = $schema->createTable('accounts');
  971. $table->addColumn('uid', 'string', [
  972. 'notnull' => true,
  973. 'length' => 64,
  974. 'default' => '',
  975. ]);
  976. $table->addColumn('data', 'text', [
  977. 'notnull' => true,
  978. 'default' => '',
  979. ]);
  980. $table->setPrimaryKey(['uid']);
  981. }
  982. return $schema;
  983. }
  984. public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
  985. /** @var ISchemaWrapper $schema */
  986. $schema = $schemaClosure();
  987. if (!$schema->hasTable('dav_properties')) {
  988. return;
  989. }
  990. $query = $this->connection->getQueryBuilder();
  991. $query->select('*')
  992. ->from('dav_properties');
  993. $insert = $this->connection->getQueryBuilder();
  994. $insert->insert('properties')
  995. ->setValue('propertypath', $insert->createParameter('propertypath'))
  996. ->setValue('propertyname', $insert->createParameter('propertyname'))
  997. ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
  998. ->setValue('userid', $insert->createParameter('userid'));
  999. $result = $query->execute();
  1000. while ($row = $result->fetch()) {
  1001. preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
  1002. $insert->setParameter('propertypath', (string) $row['propertypath'])
  1003. ->setParameter('propertyname', (string) $row['propertyname'])
  1004. ->setParameter('propertyvalue', (string) $row['propertyvalue'])
  1005. ->setParameter('userid', ($match[2] ?? ''));
  1006. $insert->execute();
  1007. }
  1008. }
  1009. }