1
0

Version1004Date20170825134824.php 13 KB

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