From 8da8c649a8afd88633e4319c4f75d1b154a0968e Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 23 May 2011 09:07:19 +0200 Subject: [PATCH] Fixed foreign keys definitions in MySQL DDL (there's a bug in MySQL where comments are handled inproperly). Updated DDL script for PostgreSQL --- .../calendar/drivers/database/sql/mysql.sql | 17 +---- .../drivers/database/sql/postgresql.sql | 64 +++++++++++++++---- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/plugins/calendar/drivers/database/sql/mysql.sql b/plugins/calendar/drivers/database/sql/mysql.sql index f0b0cea9..31fb07d8 100644 --- a/plugins/calendar/drivers/database/sql/mysql.sql +++ b/plugins/calendar/drivers/database/sql/mysql.sql @@ -19,10 +19,7 @@ CREATE TABLE `calendars` ( `color` varchar(8) NOT NULL, PRIMARY KEY(`calendar_id`), CONSTRAINT `fk_calendars_user_id` FOREIGN KEY (`user_id`) - REFERENCES `users`(`user_id`) - /*!40008 - ON DELETE CASCADE - ON UPDATE CASCADE */ + REFERENCES `users`(`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; CREATE TABLE `events` ( @@ -46,10 +43,7 @@ CREATE TABLE `events` ( `attendees` text DEFAULT NULL, PRIMARY KEY(`event_id`), CONSTRAINT `fk_events_calendar_id` FOREIGN KEY (`calendar_id`) - REFERENCES `calendars`(`calendar_id`) - /*!40008 - ON DELETE CASCADE - ON UPDATE CASCADE */ + REFERENCES `calendars`(`calendar_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; CREATE TABLE `attachments` ( @@ -61,10 +55,5 @@ CREATE TABLE `attachments` ( `data` longtext NOT NULL DEFAULT '', PRIMARY KEY(`attachment_id`), CONSTRAINT `fk_attachments_event_id` FOREIGN KEY (`event_id`) - REFERENCES `events`(`event_id`) - /*!40008 - ON DELETE CASCADE - ON UPDATE CASCADE */ + REFERENCES `events`(`event_id`) ON DELETE CASCADE ON UPDATE CASCADE ) /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */; - - diff --git a/plugins/calendar/drivers/database/sql/postgresql.sql b/plugins/calendar/drivers/database/sql/postgresql.sql index cdcc1c78..58681368 100644 --- a/plugins/calendar/drivers/database/sql/postgresql.sql +++ b/plugins/calendar/drivers/database/sql/postgresql.sql @@ -3,15 +3,33 @@ * * Plugin to add a calendar to RoundCube. * - * @version 0.2 BETA 2 + * @version 0.3 beta * @author Lazlo Westerhof * @author Albert Lee + * @author Aleksander Machniak * @url http://rc-calendar.lazlo.me * @licence GNU GPL * @copyright (c) 2010 Lazlo Westerhof - Netherlands * **/ + +CREATE SEQUENCE calendar_ids + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +CREATE TABLE calendars ( + calendar_id integer DEFAULT nextval('calendar_ids'::regclass) NOT NULL, + user_id integer NOT NULL + REFERENCES users (user_id) ON UPDATE CASCADE ON DELETE CASCADE, + name varchar(255) NOT NULL, + color varchar(8) NOT NULL, + PRIMARY KEY (calendar_id) +); + + CREATE SEQUENCE event_ids INCREMENT BY 1 NO MAXVALUE @@ -20,21 +38,41 @@ CREATE SEQUENCE event_ids CREATE TABLE events ( event_id integer DEFAULT nextval('event_ids'::regclass) NOT NULL, - user_id integer NOT NULL, + calendar_id integer NOT NULL + REFERENCES calendars (calendar_id) ON UPDATE CASCADE ON DELETE CASCADE, + recurence_id integer NOT NULL DEFAULT 0, + uid varchar(255) NOT NULL DEFAULT '', + created timestamp without time zone DEFAULT now() NOT NULL, + changed timestamp without time zone DEFAULT now(), "start" timestamp without time zone DEFAULT now() NOT NULL, "end" timestamp without time zone DEFAULT now() NOT NULL, - "title" character varying(255) NOT NULL, - "description" text NOT NULL, - "location" character varying(255) NOT NULL, - "categories" character varying(255) NOT NULL, - "all_day" smallint NOT NULL DEFAULT 0 + recurrence varchar(255) DEFAULT NULL, + title character varying(255) NOT NULL, + description text NOT NULL, + location character varying(255) NOT NULL, + categories character varying(255) NOT NULL, + all_day smallint NOT NULL DEFAULT 0, + free_busy smallint NOT NULL DEFAULT 0, + priority smallint NOT NULL DEFAULT 1, + alarms varchar(255) DEFAULT NULL, + attendees text DEFAULT NULL + PRIMARY KEY (event_id) ); -CREATE INDEX events_event_id_idx ON events USING btree (event_id); +CREATE SEQUENCE attachment_ids + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; --- --- Constraints Table `events` --- -ALTER TABLE ONLY events - ADD CONSTRAINT events_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(user_id) ON UPDATE CASCADE ON DELETE CASCADE; +CREATE TABLE attachments ( + attachment_id integer DEFAULT nextval('attachment_ids'::regclass) NOT NULL, + event_id integer NOT NULL + REFERENCES events (event_id) ON DELETE CASCADE ON UPDATE CASCADE, + filename varchar(255) NOT NULL DEFAULT '', + mimetype varchar(255) NOT NULL DEFAULT '', + size integer NOT NULL DEFAULT 0, + data text NOT NULL DEFAULT '', + PRIMARY KEY (attachment_id) +);