1
0

Version1004Date20170825134824.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\DAV\Migration;
  7. use OCP\DB\ISchemaWrapper;
  8. use OCP\Migration\IOutput;
  9. use OCP\Migration\SimpleMigrationStep;
  10. class Version1004Date20170825134824 extends SimpleMigrationStep {
  11. /**
  12. * @param IOutput $output
  13. * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
  14. * @param array $options
  15. * @return null|ISchemaWrapper
  16. * @since 13.0.0
  17. */
  18. public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
  19. /** @var ISchemaWrapper $schema */
  20. $schema = $schemaClosure();
  21. if (!$schema->hasTable('addressbooks')) {
  22. $table = $schema->createTable('addressbooks');
  23. $table->addColumn('id', 'bigint', [
  24. 'autoincrement' => true,
  25. 'notnull' => true,
  26. 'length' => 11,
  27. 'unsigned' => true,
  28. ]);
  29. $table->addColumn('principaluri', 'string', [
  30. 'notnull' => false,
  31. 'length' => 255,
  32. ]);
  33. $table->addColumn('displayname', 'string', [
  34. 'notnull' => false,
  35. 'length' => 255,
  36. ]);
  37. $table->addColumn('uri', 'string', [
  38. 'notnull' => false,
  39. 'length' => 255,
  40. ]);
  41. $table->addColumn('description', 'string', [
  42. 'notnull' => false,
  43. 'length' => 255,
  44. ]);
  45. $table->addColumn('synctoken', 'integer', [
  46. 'notnull' => true,
  47. 'default' => 1,
  48. 'length' => 10,
  49. 'unsigned' => true,
  50. ]);
  51. $table->setPrimaryKey(['id']);
  52. $table->addUniqueIndex(['principaluri', 'uri'], 'addressbook_index');
  53. }
  54. if (!$schema->hasTable('cards')) {
  55. $table = $schema->createTable('cards');
  56. $table->addColumn('id', 'bigint', [
  57. 'autoincrement' => true,
  58. 'notnull' => true,
  59. 'length' => 11,
  60. 'unsigned' => true,
  61. ]);
  62. $table->addColumn('addressbookid', 'integer', [
  63. 'notnull' => true,
  64. 'default' => 0,
  65. ]);
  66. $table->addColumn('carddata', 'blob', [
  67. 'notnull' => false,
  68. ]);
  69. $table->addColumn('uri', 'string', [
  70. 'notnull' => false,
  71. 'length' => 255,
  72. ]);
  73. $table->addColumn('lastmodified', 'bigint', [
  74. 'notnull' => false,
  75. 'length' => 11,
  76. 'unsigned' => true,
  77. ]);
  78. $table->addColumn('etag', 'string', [
  79. 'notnull' => false,
  80. 'length' => 32,
  81. ]);
  82. $table->addColumn('size', 'bigint', [
  83. 'notnull' => true,
  84. 'length' => 11,
  85. 'unsigned' => true,
  86. ]);
  87. $table->setPrimaryKey(['id']);
  88. }
  89. if (!$schema->hasTable('addressbookchanges')) {
  90. $table = $schema->createTable('addressbookchanges');
  91. $table->addColumn('id', 'bigint', [
  92. 'autoincrement' => true,
  93. 'notnull' => true,
  94. 'length' => 11,
  95. 'unsigned' => true,
  96. ]);
  97. $table->addColumn('uri', 'string', [
  98. 'notnull' => false,
  99. 'length' => 255,
  100. ]);
  101. $table->addColumn('synctoken', 'integer', [
  102. 'notnull' => true,
  103. 'default' => 1,
  104. 'length' => 10,
  105. 'unsigned' => true,
  106. ]);
  107. $table->addColumn('addressbookid', 'integer', [
  108. 'notnull' => true,
  109. ]);
  110. $table->addColumn('operation', 'smallint', [
  111. 'notnull' => true,
  112. 'length' => 1,
  113. ]);
  114. $table->setPrimaryKey(['id']);
  115. $table->addIndex(['addressbookid', 'synctoken'], 'addressbookid_synctoken');
  116. }
  117. if (!$schema->hasTable('calendarobjects')) {
  118. $table = $schema->createTable('calendarobjects');
  119. $table->addColumn('id', 'bigint', [
  120. 'autoincrement' => true,
  121. 'notnull' => true,
  122. 'length' => 11,
  123. 'unsigned' => true,
  124. ]);
  125. $table->addColumn('calendardata', 'blob', [
  126. 'notnull' => false,
  127. ]);
  128. $table->addColumn('uri', 'string', [
  129. 'notnull' => false,
  130. 'length' => 255,
  131. ]);
  132. $table->addColumn('calendarid', 'integer', [
  133. 'notnull' => true,
  134. 'length' => 10,
  135. 'unsigned' => true,
  136. ]);
  137. $table->addColumn('lastmodified', 'integer', [
  138. 'notnull' => false,
  139. 'length' => 10,
  140. 'unsigned' => true,
  141. ]);
  142. $table->addColumn('etag', 'string', [
  143. 'notnull' => false,
  144. 'length' => 32,
  145. ]);
  146. $table->addColumn('size', 'bigint', [
  147. 'notnull' => true,
  148. 'length' => 11,
  149. 'unsigned' => true,
  150. ]);
  151. $table->addColumn('componenttype', 'string', [
  152. 'notnull' => false,
  153. 'length' => 8,
  154. ]);
  155. $table->addColumn('firstoccurence', 'bigint', [
  156. 'notnull' => false,
  157. 'length' => 11,
  158. 'unsigned' => true,
  159. ]);
  160. $table->addColumn('lastoccurence', 'bigint', [
  161. 'notnull' => false,
  162. 'length' => 11,
  163. 'unsigned' => true,
  164. ]);
  165. $table->addColumn('uid', 'string', [
  166. 'notnull' => false,
  167. 'length' => 255,
  168. ]);
  169. $table->addColumn('classification', 'integer', [
  170. 'notnull' => false,
  171. 'default' => 0,
  172. ]);
  173. $table->setPrimaryKey(['id']);
  174. $table->addUniqueIndex(['calendarid', 'uri'], 'calobjects_index');
  175. }
  176. if (!$schema->hasTable('calendars')) {
  177. $table = $schema->createTable('calendars');
  178. $table->addColumn('id', 'bigint', [
  179. 'autoincrement' => true,
  180. 'notnull' => true,
  181. 'length' => 11,
  182. 'unsigned' => true,
  183. ]);
  184. $table->addColumn('principaluri', 'string', [
  185. 'notnull' => false,
  186. 'length' => 255,
  187. ]);
  188. $table->addColumn('displayname', 'string', [
  189. 'notnull' => false,
  190. 'length' => 255,
  191. ]);
  192. $table->addColumn('uri', 'string', [
  193. 'notnull' => false,
  194. 'length' => 255,
  195. ]);
  196. $table->addColumn('synctoken', 'integer', [
  197. 'notnull' => true,
  198. 'default' => 1,
  199. 'unsigned' => true,
  200. ]);
  201. $table->addColumn('description', 'string', [
  202. 'notnull' => false,
  203. 'length' => 255,
  204. ]);
  205. $table->addColumn('calendarorder', 'integer', [
  206. 'notnull' => true,
  207. 'default' => 0,
  208. 'unsigned' => true,
  209. ]);
  210. $table->addColumn('calendarcolor', 'string', [
  211. 'notnull' => false,
  212. ]);
  213. $table->addColumn('timezone', 'text', [
  214. 'notnull' => false,
  215. ]);
  216. $table->addColumn('components', 'string', [
  217. 'notnull' => false,
  218. 'length' => 64,
  219. ]);
  220. $table->addColumn('transparent', 'smallint', [
  221. 'notnull' => true,
  222. 'length' => 1,
  223. 'default' => 0,
  224. ]);
  225. $table->setPrimaryKey(['id']);
  226. $table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index');
  227. } else {
  228. $table = $schema->getTable('calendars');
  229. $table->changeColumn('components', [
  230. 'notnull' => false,
  231. 'length' => 64,
  232. ]);
  233. }
  234. if (!$schema->hasTable('calendarchanges')) {
  235. $table = $schema->createTable('calendarchanges');
  236. $table->addColumn('id', 'bigint', [
  237. 'autoincrement' => true,
  238. 'notnull' => true,
  239. 'length' => 11,
  240. 'unsigned' => true,
  241. ]);
  242. $table->addColumn('uri', 'string', [
  243. 'notnull' => false,
  244. 'length' => 255,
  245. ]);
  246. $table->addColumn('synctoken', 'integer', [
  247. 'notnull' => true,
  248. 'default' => 1,
  249. 'length' => 10,
  250. 'unsigned' => true,
  251. ]);
  252. $table->addColumn('calendarid', 'integer', [
  253. 'notnull' => true,
  254. ]);
  255. $table->addColumn('operation', 'smallint', [
  256. 'notnull' => true,
  257. 'length' => 1,
  258. ]);
  259. $table->setPrimaryKey(['id']);
  260. $table->addIndex(['calendarid', 'synctoken'], 'calendarid_synctoken');
  261. }
  262. if (!$schema->hasTable('calendarsubscriptions')) {
  263. $table = $schema->createTable('calendarsubscriptions');
  264. $table->addColumn('id', 'bigint', [
  265. 'autoincrement' => true,
  266. 'notnull' => true,
  267. 'length' => 11,
  268. 'unsigned' => true,
  269. ]);
  270. $table->addColumn('uri', 'string', [
  271. 'notnull' => false,
  272. ]);
  273. $table->addColumn('principaluri', 'string', [
  274. 'notnull' => false,
  275. 'length' => 255,
  276. ]);
  277. $table->addColumn('source', 'string', [
  278. 'notnull' => false,
  279. 'length' => 255,
  280. ]);
  281. $table->addColumn('displayname', 'string', [
  282. 'notnull' => false,
  283. 'length' => 100,
  284. ]);
  285. $table->addColumn('refreshrate', 'string', [
  286. 'notnull' => false,
  287. 'length' => 10,
  288. ]);
  289. $table->addColumn('calendarorder', 'integer', [
  290. 'notnull' => true,
  291. 'default' => 0,
  292. 'unsigned' => true,
  293. ]);
  294. $table->addColumn('calendarcolor', 'string', [
  295. 'notnull' => false,
  296. ]);
  297. $table->addColumn('striptodos', 'smallint', [
  298. 'notnull' => false,
  299. 'length' => 1,
  300. ]);
  301. $table->addColumn('stripalarms', 'smallint', [
  302. 'notnull' => false,
  303. 'length' => 1,
  304. ]);
  305. $table->addColumn('stripattachments', 'smallint', [
  306. 'notnull' => false,
  307. 'length' => 1,
  308. ]);
  309. $table->addColumn('lastmodified', 'integer', [
  310. 'notnull' => false,
  311. 'unsigned' => true,
  312. ]);
  313. $table->setPrimaryKey(['id']);
  314. $table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index');
  315. } else {
  316. $table = $schema->getTable('calendarsubscriptions');
  317. $table->changeColumn('lastmodified', [
  318. 'notnull' => false,
  319. 'unsigned' => true,
  320. ]);
  321. }
  322. if (!$schema->hasTable('schedulingobjects')) {
  323. $table = $schema->createTable('schedulingobjects');
  324. $table->addColumn('id', 'bigint', [
  325. 'autoincrement' => true,
  326. 'notnull' => true,
  327. 'length' => 11,
  328. 'unsigned' => true,
  329. ]);
  330. $table->addColumn('principaluri', 'string', [
  331. 'notnull' => false,
  332. 'length' => 255,
  333. ]);
  334. $table->addColumn('calendardata', 'blob', [
  335. 'notnull' => false,
  336. ]);
  337. $table->addColumn('uri', 'string', [
  338. 'notnull' => false,
  339. 'length' => 255,
  340. ]);
  341. $table->addColumn('lastmodified', 'integer', [
  342. 'notnull' => false,
  343. 'unsigned' => true,
  344. ]);
  345. $table->addColumn('etag', 'string', [
  346. 'notnull' => false,
  347. 'length' => 32,
  348. ]);
  349. $table->addColumn('size', 'bigint', [
  350. 'notnull' => true,
  351. 'length' => 11,
  352. 'unsigned' => true,
  353. ]);
  354. $table->setPrimaryKey(['id']);
  355. $table->addIndex(['principaluri'], 'schedulobj_principuri_index');
  356. $table->addIndex(['lastmodified'], 'schedulobj_lastmodified_idx');
  357. }
  358. if (!$schema->hasTable('cards_properties')) {
  359. $table = $schema->createTable('cards_properties');
  360. $table->addColumn('id', 'bigint', [
  361. 'autoincrement' => true,
  362. 'notnull' => true,
  363. 'length' => 11,
  364. 'unsigned' => true,
  365. ]);
  366. $table->addColumn('addressbookid', 'bigint', [
  367. 'notnull' => true,
  368. 'length' => 11,
  369. 'default' => 0,
  370. ]);
  371. $table->addColumn('cardid', 'bigint', [
  372. 'notnull' => true,
  373. 'length' => 11,
  374. 'default' => 0,
  375. 'unsigned' => true,
  376. ]);
  377. $table->addColumn('name', 'string', [
  378. 'notnull' => false,
  379. 'length' => 64,
  380. ]);
  381. $table->addColumn('value', 'string', [
  382. 'notnull' => false,
  383. 'length' => 255,
  384. ]);
  385. $table->addColumn('preferred', 'integer', [
  386. 'notnull' => true,
  387. 'length' => 4,
  388. 'default' => 1,
  389. ]);
  390. $table->setPrimaryKey(['id']);
  391. $table->addIndex(['cardid'], 'card_contactid_index');
  392. $table->addIndex(['name'], 'card_name_index');
  393. $table->addIndex(['value'], 'card_value_index');
  394. }
  395. if (!$schema->hasTable('calendarobjects_props')) {
  396. $table = $schema->createTable('calendarobjects_props');
  397. $table->addColumn('id', 'bigint', [
  398. 'autoincrement' => true,
  399. 'notnull' => true,
  400. 'length' => 11,
  401. 'unsigned' => true,
  402. ]);
  403. $table->addColumn('calendarid', 'bigint', [
  404. 'notnull' => true,
  405. 'length' => 11,
  406. 'default' => 0,
  407. ]);
  408. $table->addColumn('objectid', 'bigint', [
  409. 'notnull' => true,
  410. 'length' => 11,
  411. 'default' => 0,
  412. 'unsigned' => true,
  413. ]);
  414. $table->addColumn('name', 'string', [
  415. 'notnull' => false,
  416. 'length' => 64,
  417. ]);
  418. $table->addColumn('parameter', 'string', [
  419. 'notnull' => false,
  420. 'length' => 64,
  421. ]);
  422. $table->addColumn('value', 'string', [
  423. 'notnull' => false,
  424. 'length' => 255,
  425. ]);
  426. $table->setPrimaryKey(['id']);
  427. $table->addIndex(['objectid'], 'calendarobject_index');
  428. $table->addIndex(['name'], 'calendarobject_name_index');
  429. $table->addIndex(['value'], 'calendarobject_value_index');
  430. }
  431. if (!$schema->hasTable('dav_shares')) {
  432. $table = $schema->createTable('dav_shares');
  433. $table->addColumn('id', 'bigint', [
  434. 'autoincrement' => true,
  435. 'notnull' => true,
  436. 'length' => 11,
  437. 'unsigned' => true,
  438. ]);
  439. $table->addColumn('principaluri', 'string', [
  440. 'notnull' => false,
  441. 'length' => 255,
  442. ]);
  443. $table->addColumn('type', 'string', [
  444. 'notnull' => false,
  445. 'length' => 255,
  446. ]);
  447. $table->addColumn('access', 'smallint', [
  448. 'notnull' => false,
  449. 'length' => 1,
  450. ]);
  451. $table->addColumn('resourceid', 'integer', [
  452. 'notnull' => true,
  453. 'unsigned' => true,
  454. ]);
  455. $table->addColumn('publicuri', 'string', [
  456. 'notnull' => false,
  457. 'length' => 255,
  458. ]);
  459. $table->setPrimaryKey(['id']);
  460. $table->addUniqueIndex(['principaluri', 'resourceid', 'type', 'publicuri'], 'dav_shares_index');
  461. // modified on 2024-6-21 to add performance improving indices on new instances
  462. $table->addIndex(['resourceid', 'type'], 'dav_shares_resourceid_type');
  463. $table->addIndex(['resourceid', 'access'], 'dav_shares_resourceid_access');
  464. }
  465. return $schema;
  466. }
  467. }