-- Schema: bird__movie_3
CREATE SCHEMA IF NOT EXISTS "bird__movie_3";

-- Table: actor
CREATE TABLE "bird__movie_3"."actor" (
    "actor_id" BIGINT NOT NULL,
    "first_name" TEXT NOT NULL,
    "last_name" TEXT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "actor_pkey" PRIMARY KEY ("actor_id")
);

-- Table: address
CREATE TABLE "bird__movie_3"."address" (
    "address_id" BIGINT NOT NULL,
    "address" TEXT NOT NULL,
    "address2" TEXT,
    "district" TEXT NOT NULL,
    "city_id" BIGINT NOT NULL,
    "postal_code" TEXT,
    "phone" TEXT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "address_pkey" PRIMARY KEY ("address_id")
);

-- Table: category
CREATE TABLE "bird__movie_3"."category" (
    "category_id" BIGINT NOT NULL,
    "name" TEXT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "category_pkey" PRIMARY KEY ("category_id")
);

-- Table: city
CREATE TABLE "bird__movie_3"."city" (
    "city_id" BIGINT NOT NULL,
    "city" TEXT NOT NULL,
    "country_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "city_pkey" PRIMARY KEY ("city_id")
);

-- Table: country
CREATE TABLE "bird__movie_3"."country" (
    "country_id" BIGINT NOT NULL,
    "country" TEXT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "country_pkey" PRIMARY KEY ("country_id")
);

-- Table: customer
CREATE TABLE "bird__movie_3"."customer" (
    "customer_id" BIGINT NOT NULL,
    "store_id" BIGINT NOT NULL,
    "first_name" TEXT NOT NULL,
    "last_name" TEXT NOT NULL,
    "email" TEXT,
    "address_id" BIGINT NOT NULL,
    "active" BIGINT NOT NULL DEFAULT 1,
    "create_date" TIMESTAMP NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "customer_pkey" PRIMARY KEY ("customer_id")
);

-- Table: film
CREATE TABLE "bird__movie_3"."film" (
    "film_id" BIGINT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "release_year" TEXT,
    "language_id" BIGINT NOT NULL,
    "original_language_id" BIGINT,
    "rental_duration" BIGINT NOT NULL DEFAULT 3,
    "rental_rate" DOUBLE PRECISION NOT NULL DEFAULT 4.99,
    "length" BIGINT,
    "replacement_cost" DOUBLE PRECISION NOT NULL DEFAULT 19.99,
    "rating" TEXT DEFAULT 'G'::text,
    "special_features" TEXT,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "film_pkey" PRIMARY KEY ("film_id")
);

-- Table: film_actor
CREATE TABLE "bird__movie_3"."film_actor" (
    "actor_id" BIGINT NOT NULL,
    "film_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "film_actor_pkey" PRIMARY KEY ("actor_id", "film_id")
);

-- Table: film_category
CREATE TABLE "bird__movie_3"."film_category" (
    "film_id" BIGINT NOT NULL,
    "category_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "film_category_pkey" PRIMARY KEY ("film_id", "category_id")
);

-- Table: film_text
CREATE TABLE "bird__movie_3"."film_text" (
    "film_id" BIGINT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    CONSTRAINT "film_text_pkey" PRIMARY KEY ("film_id")
);

-- Table: inventory
CREATE TABLE "bird__movie_3"."inventory" (
    "inventory_id" BIGINT NOT NULL,
    "film_id" BIGINT NOT NULL,
    "store_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "inventory_pkey" PRIMARY KEY ("inventory_id")
);

-- Table: language
CREATE TABLE "bird__movie_3"."language" (
    "language_id" BIGINT NOT NULL,
    "name" TEXT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "language_pkey" PRIMARY KEY ("language_id")
);

-- Table: payment
CREATE TABLE "bird__movie_3"."payment" (
    "payment_id" BIGINT NOT NULL,
    "customer_id" BIGINT NOT NULL,
    "staff_id" BIGINT NOT NULL,
    "rental_id" BIGINT,
    "amount" DOUBLE PRECISION NOT NULL,
    "payment_date" TIMESTAMP NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "payment_pkey" PRIMARY KEY ("payment_id")
);

-- Table: rental
CREATE TABLE "bird__movie_3"."rental" (
    "rental_id" BIGINT NOT NULL,
    "rental_date" TIMESTAMP NOT NULL,
    "inventory_id" BIGINT NOT NULL,
    "customer_id" BIGINT NOT NULL,
    "return_date" TIMESTAMP,
    "staff_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "rental_pkey" PRIMARY KEY ("rental_id"),
    CONSTRAINT "rental_rental_date_inventory_id_customer_id_key" UNIQUE ("rental_date", "inventory_id", "customer_id")
);

-- Table: staff
CREATE TABLE "bird__movie_3"."staff" (
    "staff_id" BIGINT NOT NULL,
    "first_name" TEXT NOT NULL,
    "last_name" TEXT NOT NULL,
    "address_id" BIGINT NOT NULL,
    "picture" BYTEA,
    "email" TEXT,
    "store_id" BIGINT NOT NULL,
    "active" BIGINT NOT NULL DEFAULT 1,
    "username" TEXT NOT NULL,
    "password" TEXT,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "staff_pkey" PRIMARY KEY ("staff_id")
);

-- Table: store
CREATE TABLE "bird__movie_3"."store" (
    "store_id" BIGINT NOT NULL,
    "manager_staff_id" BIGINT NOT NULL,
    "address_id" BIGINT NOT NULL,
    "last_update" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "store_pkey" PRIMARY KEY ("store_id")
);
