Nessuna descrizione
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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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` int(11) NOT NULL auto_increment,
  7. `name` varchar(50) NOT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  10. CREATE TABLE IF NOT EXISTS `virtual_users` (
  11. `id` int(11) NOT NULL auto_increment,
  12. `domain_id` int(11) NOT NULL,
  13. `password` varchar(106) NOT NULL,
  14. `email` varchar(100) NOT NULL,
  15. PRIMARY KEY (`id`),
  16. UNIQUE KEY `email` (`email`),
  17. FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
  18. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  19. CREATE TABLE IF NOT EXISTS `virtual_aliases` (
  20. `id` int(11) NOT NULL auto_increment,
  21. `domain_id` int(11) NOT NULL,
  22. `source` varchar(100) NOT NULL,
  23. `destination` varchar(100) NOT NULL,
  24. PRIMARY KEY (`id`),
  25. FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
  26. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  27. {% for virtual_domain in mail_virtual_domains %}
  28. INSERT INTO {{ mail_mysql_database }}.`virtual_domains` (`id`, `name`)
  29. VALUES ('{{ virtual_domain.pk_id }}', '{{ virtual_domain.name }}');
  30. {% endfor %}
  31. {% for virtual_user in mail_virtual_users %}
  32. INSERT INTO {{ mail_mysql_database }}.`virtual_users` (`domain_id`, `password` , `email`)
  33. VALUES (
  34. '{{ virtual_user.domain_pk_id }}',
  35. '{{ virtual_user.password_hash }}',
  36. '{{ virtual_user.account }}@{{ virtual_user.domain }}'
  37. );
  38. {% endfor %}
  39. {% if mail_virtual_aliases is defined %}
  40. {% for virtual_alias in mail_virtual_aliases %}
  41. INSERT INTO {{ mail_mysql_database }}.`virtual_aliases` (`domain_id`, `source`, `destination`)
  42. VALUES ('{{ virtual_alias.domain_pk_id }}', '{{ virtual_alias.source }}', '{{virtual_alias.destination }}');
  43. {% endfor %}
  44. {% endif %}