-- Generated for Oracle
-- Review users, roles and physical storage settings before production use.

-- Oracle schema/user "main" must already exist.

CREATE TABLE "main"."address" (
  "ID" NUMBER(19) GENERATED BY DEFAULT AS IDENTITY NOT NULL,
  "CITY" VARCHAR2(255 CHAR) NOT NULL,
  "COUNTRY" VARCHAR2(255 CHAR) NOT NULL,
  "HOUSE_NUMBER" VARCHAR2(255 CHAR) NOT NULL,
  "STREET" VARCHAR2(255 CHAR) NOT NULL,
  "ZIP_CODE" VARCHAR2(255 CHAR) NOT NULL,
  CONSTRAINT "pk_main_address" PRIMARY KEY ("ID")
);

CREATE TABLE "main"."contract" (
  "ID" NUMBER(19) GENERATED BY DEFAULT AS IDENTITY NOT NULL,
  "ID_CUSTOMER" NUMBER(19) NOT NULL,
  "DURATION_MONTHS" NUMBER(10) NOT NULL,
  "AMOUNT" BINARY_FLOAT NOT NULL,
  "CONTRACT_NUMBER" VARCHAR2(255 CHAR) NOT NULL,
  "CONTRACT_DATE" TIMESTAMP WITH TIME ZONE NOT NULL,
  CONSTRAINT "pk_main_contract" PRIMARY KEY ("ID")
);

CREATE TABLE "main"."customer" (
  "ID" NUMBER(19) GENERATED BY DEFAULT AS IDENTITY NOT NULL,
  "ID_ADDRESS" NUMBER(19) NOT NULL,
  "EMAIL" VARCHAR2(255 CHAR) NOT NULL,
  "PHONE" VARCHAR2(255 CHAR) NOT NULL,
  "FIRST_NAME" VARCHAR2(255 CHAR) NOT NULL,
  "LAST_NAME" VARCHAR2(255 CHAR) NOT NULL,
  CONSTRAINT "pk_main_customer" PRIMARY KEY ("ID")
);

-- Foreign keys
ALTER TABLE "main"."contract" ADD CONSTRAINT "fk_main_contract_ID_CUSTOMER" FOREIGN KEY ("ID_CUSTOMER") REFERENCES "main"."customer" ("ID");
ALTER TABLE "main"."customer" ADD CONSTRAINT "fk_main_customer_ID_ADDRESS" FOREIGN KEY ("ID_ADDRESS") REFERENCES "main"."address" ("ID");
