Version1004Date20170825134824.php 13 KB

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