coreos-home-server/service/dovecot/service/mariadb-migrate.sql
Alex Palaistras f877a72e83 Flatten directory structures
This commit contains a fairly large diff for a fairly small change:
moving the `config/common` directory to `host/base` to better reflect
its intended use, and promoting `config/service` to the root directory.

These changes unlock some improvements in `coreos-home-server-update`
processes, which will (assuming `/etc/coreos-home-server/base` exists)
keep host-wide systemd services in sync in addition to service-specific
ones.

Changes have been make to the `Makefile` and a few other places where
`config/common` was referenced, but most of this work is renames that
are not intended to break compatibility with new or running servers.
2022-01-15 11:43:33 +00:00

57 lines
2.0 KiB
PL/PgSQL

-- Create default database.
CREATE DATABASE IF NOT EXISTS `${DOVECOT_DATABASE_NAME}`;
-- Create default user with pre-defined password.
CREATE USER IF NOT EXISTS '${DOVECOT_DATABASE_USERNAME}'@'%' IDENTIFIED BY '${DOVECOT_DATABASE_PASSWORD}';
GRANT ALL PRIVILEGES ON `${DOVECOT_DATABASE_NAME}`.* TO '${DOVECOT_DATABASE_USERNAME}'@'%';
FLUSH PRIVILEGES;
USE `${DOVECOT_DATABASE_NAME}`;
BEGIN;
-- Create default schema.
CREATE TABLE IF NOT EXISTS `users` (
`username` VARCHAR(255) NOT NULL PRIMARY KEY,
`password` VARCHAR(255) NOT NULL,
`maildir` VARCHAR(255) NOT NULL,
`home` VARCHAR(255) NOT NULL DEFAULT '/var/mail/virtual',
`uid` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 5000,
`gid` SMALLINT(5) UNSIGNED NOT NULL DEFAULT 5000,
`enabled` TINYINT(1) NOT NULL DEFAULT 1
);
CREATE TABLE IF NOT EXISTS `domains` (
`id` SMALLINT(6) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`domain` VARCHAR(255) NOT NULL,
`transport` VARCHAR(255) NOT NULL DEFAULT 'virtual:',
`enabled` TINYINT(1) NOT NULL DEFAULT 1
);
CREATE TABLE IF NOT EXISTS `aliases` (
`id` SMALLINT(3) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`mail` VARCHAR(255) NOT NULL,
`destination` VARCHAR(255) NOT NULL,
`enabled` TINYINT(1) NOT NULL DEFAULT 1,
UNIQUE KEY `mail` (`mail`)
);
-- Create default, required entries.
INSERT INTO `domains` (domain)
VALUES ('localhost'),
('localhost.localdomain');
INSERT INTO `aliases` (`mail`, `destination`)
VALUES ('postmaster@localhost' ,'root@localhost'),
('sysadmin@localhost' ,'root@localhost'),
('webmaster@localhost' ,'root@localhost'),
('abuse@localhost' ,'root@localhost'),
('root@localhost' ,'root@localhost'),
('@localhost' ,'root@localhost'),
('@localhost.localdomain','@localhost');
INSERT INTO `users` (`username`, `password`, `maildir`)
VALUES ('root@localhost', encrypt(MD5(RAND()), CONCAT('$5$', MD5(RAND()))), 'root/');
COMMIT;