12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- -- If tables are not dropped, have to truncate before insert or use "insert or replace" (not postgres compatible)
-
- DROP TABLE IF EXISTS "virtual_users";
- DROP TABLE IF EXISTS "virtual_aliases";
- DROP TABLE IF EXISTS "virtual_domains";
-
- CREATE TABLE IF NOT EXISTS "virtual_domains" (
- "id" SERIAL,
- "name" TEXT NOT NULL,
- PRIMARY KEY ("id")
- );
-
- CREATE UNIQUE INDEX name_idx ON virtual_domains (name);
-
- CREATE TABLE IF NOT EXISTS "virtual_users" (
- "id" SERIAL,
- "username" TEXT NOT NULL,
- "domain" TEXT NOT NULL,
- "password" TEXT NOT NULL,
- "sendonly" boolean DEFAULT FALSE,
- PRIMARY KEY ("id")
- );
-
- CREATE UNIQUE INDEX email_idx ON virtual_users (username, domain);
-
- CREATE TABLE IF NOT EXISTS "virtual_aliases" (
- "id" SERIAL,
- "source" TEXT NOT NULL,
- "destination" TEXT NOT NULL,
- PRIMARY KEY ("id")
- );
-
- CREATE INDEX source_idx ON virtual_aliases (source);
-
- {% for virtual_domain in virtual_domains %}
- INSERT INTO "virtual_domains" ("name")
- VALUES ('{{ virtual_domain.name }}');
- {% endfor %}
-
- {% for virtual_user in mail_virtual_users %}
- INSERT INTO "virtual_users" ("username", "domain", "password" , "sendonly")
- VALUES (
- '{{ virtual_user.account }}',
- '{{ virtual_user.domain }}',
- '{{ virtual_user.password }}',
- '{{ virtual_user.sendonly }}'
- );
- {% endfor %}
-
- {% if mail_virtual_aliases is defined %}
- {% for virtual_alias in mail_virtual_aliases %}
- INSERT INTO "virtual_aliases" ("source", "destination")
- VALUES (
- '{{ virtual_alias.source }}',
- '{{ virtual_alias.destination }}'
- );
- {% endfor %}
- {% endif %}
|