Version1004Date20170825134824.php 13 KB

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