Config generator initialization fixed
[ipypbx] / src / ipypbx / create.sql
index 4c95e8e..3a573f8 100644 (file)
@@ -1,9 +1,8 @@
-BEGIN;
 CREATE TABLE "ipypbxweb_connection" (
     "id" integer NOT NULL PRIMARY KEY,
     "name" varchar(100) NOT NULL,
     "local_ip_address" char(15) NOT NULL,
-    "local_port" integer unsigned NOT NULL,
+    "local_port" integer unsigned NOT NULL UNIQUE,
     "freeswitch_ip_address" char(15) NOT NULL,
     "freeswitch_port" integer unsigned NOT NULL
 )
@@ -24,6 +23,7 @@ CREATE TABLE "ipypbxweb_sipprofile" (
 ;
 CREATE TABLE "ipypbxweb_domain" (
     "id" integer NOT NULL PRIMARY KEY,
+    "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"),
     "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"),
     "host_name" varchar(100) NOT NULL,
     "is_active" bool NOT NULL
@@ -31,12 +31,14 @@ CREATE TABLE "ipypbxweb_domain" (
 ;
 CREATE TABLE "ipypbxweb_gateway" (
     "id" integer NOT NULL PRIMARY KEY,
+    "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"),
     "sip_profile_id" integer NOT NULL REFERENCES "ipypbxweb_sipprofile" ("id"),
     "name" varchar(100) NOT NULL,
     "username" varchar(100) NOT NULL,
     "password" varchar(100) NOT NULL,
     "realm" varchar(100) NOT NULL,
     "from_domain" varchar(100) NOT NULL,
+    "extension" varchar(100) NOT NULL,
     "expire_in_seconds" integer unsigned NOT NULL,
     "retry_in_seconds" integer unsigned NOT NULL,
     "caller_id_in_from_field" bool NOT NULL,
@@ -45,24 +47,31 @@ CREATE TABLE "ipypbxweb_gateway" (
 ;
 CREATE TABLE "ipypbxweb_endpoint" (
     "id" integer NOT NULL PRIMARY KEY,
+    "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"),
     "user_id" varchar(100) NOT NULL,
     "password" varchar(100) NOT NULL,
-    "domain" varchar(100) NOT NULL,
+    "domain_id" integer NOT NULL REFERENCES "ipypbxweb_domain" ("id"),
     "is_active" bool NOT NULL
 )
 ;
 CREATE TABLE "ipypbxweb_extension" (
     "id" integer NOT NULL PRIMARY KEY,
+    "connection_id" integer NOT NULL REFERENCES "ipypbxweb_connection" ("id"),
     "destination_match" varchar(100) NOT NULL,
     "xml_dialplan" text NOT NULL,
-    "domain" varchar(100) NOT NULL,
-    "endpoint_id" integer NOT NULL REFERENCES "ipypbxweb_endpoint" ("id"),
+    "domain_id" integer REFERENCES "ipypbxweb_domain" ("id"),
+    "endpoint_id" integer REFERENCES "ipypbxweb_endpoint" ("id"),
     "authenticate_calls" bool NOT NULL,
     "is_active" bool NOT NULL
 )
 ;
 CREATE INDEX "ipypbxweb_sipprofile_connection_id" ON "ipypbxweb_sipprofile" ("connection_id");
+CREATE INDEX "ipypbxweb_domain_connection_id" ON "ipypbxweb_domain" ("connection_id");
 CREATE INDEX "ipypbxweb_domain_sip_profile_id" ON "ipypbxweb_domain" ("sip_profile_id");
+CREATE INDEX "ipypbxweb_gateway_connection_id" ON "ipypbxweb_gateway" ("connection_id");
 CREATE INDEX "ipypbxweb_gateway_sip_profile_id" ON "ipypbxweb_gateway" ("sip_profile_id");
-CREATE INDEX "ipypbxweb_extension_endpoint_id" ON "ipypbxweb_extension" ("endpoint_id");
-COMMIT;
+CREATE INDEX "ipypbxweb_endpoint_connection_id" ON "ipypbxweb_endpoint" ("connection_id");
+CREATE INDEX "ipypbxweb_endpoint_domain_id" ON "ipypbxweb_endpoint" ("domain_id");
+CREATE INDEX "ipypbxweb_extension_connection_id" ON "ipypbxweb_extension" ("connection_id");
+CREATE INDEX "ipypbxweb_extension_domain_id" ON "ipypbxweb_extension" ("domain_id");
+CREATE INDEX "ipypbxweb_extension_endpoint_id" ON "ipypbxweb_extension" ("endpoint_id");
\ No newline at end of file