CREATE TABLE "documents"( 
    "id"                        bigserial PRIMARY KEY,
    "name"                      VARCHAR NOT NULL,
    "description"               VARCHAR NOT NULL,
    "documentusage"             VARCHAR NOT NULL,
    "iscrop"                    BOOLEAN NOT NULL,
    "isglobal"                  BOOLEAN NOT NULL,
    "created_at"                TIMESTAMPTZ NOT NULL DEFAULT(now())
);

CREATE TABLE "document_crops"( 
    "id"                        bigserial PRIMARY KEY,
    "crop_id"                   INT NOT NULL,
    "document_id"               INT NOT NULL,
    "created_at"                TIMESTAMPTZ NOT NULL DEFAULT(now())
);

ALTER TABLE "document_crops" ADD FOREIGN KEY ("crop_id") REFERENCES "crops" ("id");
ALTER TABLE "document_crops" ADD FOREIGN KEY ("document_id") REFERENCES "documents" ("id");

CREATE TABLE "document_countries"( 
    "id"                        bigserial PRIMARY KEY,
    "country_id"                INT NOT NULL,
    "document_id"               INT NOT NULL,
    "created_at"                TIMESTAMPTZ NOT NULL DEFAULT(now())
);
ALTER TABLE "document_countries" ADD FOREIGN KEY ("country_id") REFERENCES "countries" ("id");
ALTER TABLE "document_countries" ADD FOREIGN KEY ("document_id") REFERENCES "documents" ("id");







