diff --git a/migrations/20180211052642-mailboxes-alter-domains-constraint.js b/migrations/20180211052642-mailboxes-alter-domains-constraint.js new file mode 100644 index 000000000..63740bcb3 --- /dev/null +++ b/migrations/20180211052642-mailboxes-alter-domains-constraint.js @@ -0,0 +1,19 @@ +'use strict'; + +var async = require('async'); + +exports.up = function(db, callback) { + async.series([ + db.runSql.bind(db, 'START TRANSACTION;'), + db.runSql.bind(db, 'ALTER TABLE mailboxes DROP FOREIGN KEY mailboxes_domain_constraint'), + db.runSql.bind(db, 'ALTER TABLE mailboxes ADD CONSTRAINT mailboxes_domain_constraint FOREIGN KEY(domain) REFERENCES mail(domain)'), + db.runSql.bind(db, 'COMMIT') + ], callback); +}; + +exports.down = function(db, callback) { + db.runSql('ALTER TABLE mailboxes DROP FOREIGN KEY mailboxes_domain_constraint', function (error) { + if (error) console.error(error); + callback(error); + }); +}; diff --git a/migrations/schema.sql b/migrations/schema.sql index 9ac57a539..c74e6aa3a 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -133,21 +133,6 @@ CREATE TABLE IF NOT EXISTS eventlog( PRIMARY KEY (id)); -/* Future fields: - * accessRestriction - to determine who can access it. So this has foreign keys - * quota - per mailbox quota -*/ -CREATE TABLE IF NOT EXISTS mailboxes( - name VARCHAR(128) NOT NULL, - ownerId VARCHAR(128) NOT NULL, /* app id or user id or group id */ - ownerType VARCHAR(16) NOT NULL, /* 'app' or 'user' or 'group' */ - aliasTarget VARCHAR(128), /* the target name type is an alias */ - creationTime TIMESTAMP, - domain VARCHAR(128), - - FOREIGN KEY(domain) REFERENCES domains(domain), - UNIQUE (name, domain)); - CREATE TABLE IF NOT EXISTS domains( domain VARCHAR(128) NOT NULL UNIQUE, /* if this needs to be larger, InnoDB has a limit of 767 bytes for PRIMARY KEY values! */ zoneName VARCHAR(128) NOT NULL, /* this mostly contains the domain itself again */ @@ -173,4 +158,18 @@ CREATE TABLE IF NOT EXISTS mail( CHARACTER SET utf8 COLLATE utf8_bin; +/* Future fields: + * accessRestriction - to determine who can access it. So this has foreign keys + * quota - per mailbox quota +*/ +CREATE TABLE IF NOT EXISTS mailboxes( + name VARCHAR(128) NOT NULL, + ownerId VARCHAR(128) NOT NULL, /* app id or user id or group id */ + ownerType VARCHAR(16) NOT NULL, /* 'app' or 'user' or 'group' */ + aliasTarget VARCHAR(128), /* the target name type is an alias */ + creationTime TIMESTAMP, + domain VARCHAR(128), + + FOREIGN KEY(domain) REFERENCES mail(domain), + UNIQUE (name, domain));