Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mailserver.sql.j2 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. -- If tables are not dropped, have to truncate before insert or use "insert or replace" (not postgres compatible)
  2. DROP TABLE IF EXISTS "virtual_users";
  3. DROP TABLE IF EXISTS "virtual_aliases";
  4. DROP TABLE IF EXISTS "virtual_domains";
  5. CREATE TABLE IF NOT EXISTS "virtual_domains" (
  6. "id" SERIAL,
  7. "name" TEXT NOT NULL,
  8. PRIMARY KEY ("id")
  9. );
  10. CREATE UNIQUE INDEX name_idx ON virtual_domains (name);
  11. CREATE TABLE IF NOT EXISTS "virtual_users" (
  12. "id" SERIAL,
  13. "domain_id" int NOT NULL,
  14. "password" TEXT NOT NULL,
  15. "email" TEXT NOT NULL UNIQUE,
  16. PRIMARY KEY ("id"),
  17. FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
  18. );
  19. CREATE UNIQUE INDEX email_idx ON virtual_users (email);
  20. CREATE TABLE IF NOT EXISTS "virtual_aliases" (
  21. "id" SERIAL,
  22. "domain_id" int NOT NULL,
  23. "source" TEXT NOT NULL,
  24. "destination" TEXT NOT NULL,
  25. PRIMARY KEY ("id"),
  26. FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
  27. );
  28. CREATE INDEX source_idx ON virtual_aliases (source);
  29. {% for virtual_domain in mail_virtual_domains %}
  30. INSERT INTO "virtual_domains" ("id", "name")
  31. VALUES ('{{ virtual_domain.pk_id }}', '{{ virtual_domain.name }}');
  32. {% endfor %}
  33. {% for virtual_user in mail_virtual_users %}
  34. INSERT INTO "virtual_users" ("domain_id", "password" , "email")
  35. VALUES (
  36. '{{ virtual_user.domain_pk_id }}',
  37. '{{ virtual_user.password_hash }}',
  38. '{{ virtual_user.account }}@{{ virtual_user.domain }}'
  39. );
  40. {% endfor %}
  41. {% if mail_virtual_aliases is defined %}
  42. {% for virtual_alias in mail_virtual_aliases %}
  43. INSERT INTO "virtual_aliases" ("domain_id", "source", "destination")
  44. VALUES ('{{ virtual_alias.domain_pk_id }}', '{{ virtual_alias.source }}', '{{virtual_alias.destination }}');
  45. {% endfor %}
  46. {% endif %}