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.
45 lines
1.1 KiB
45 lines
1.1 KiB
2 years ago
|
-- CreateTable
|
||
|
CREATE TABLE "Country" (
|
||
|
"id" TEXT NOT NULL,
|
||
|
"name" TEXT NOT NULL,
|
||
|
"code" TEXT NOT NULL,
|
||
|
|
||
|
CONSTRAINT "Country_pkey" PRIMARY KEY ("id")
|
||
|
);
|
||
|
|
||
|
-- CreateTable
|
||
|
CREATE TABLE "State" (
|
||
|
"id" TEXT NOT NULL,
|
||
|
"name" TEXT NOT NULL,
|
||
|
"countryId" TEXT NOT NULL,
|
||
|
|
||
|
CONSTRAINT "State_pkey" PRIMARY KEY ("id")
|
||
|
);
|
||
|
|
||
|
-- CreateTable
|
||
|
CREATE TABLE "City" (
|
||
|
"id" TEXT NOT NULL,
|
||
|
"name" TEXT NOT NULL,
|
||
|
"stateId" TEXT NOT NULL,
|
||
|
|
||
|
CONSTRAINT "City_pkey" PRIMARY KEY ("id")
|
||
|
);
|
||
|
|
||
|
-- CreateIndex
|
||
|
CREATE UNIQUE INDEX "Country_name_key" ON "Country"("name");
|
||
|
|
||
|
-- CreateIndex
|
||
|
CREATE UNIQUE INDEX "Country_code_key" ON "Country"("code");
|
||
|
|
||
|
-- CreateIndex
|
||
|
CREATE UNIQUE INDEX "State_name_countryId_key" ON "State"("name", "countryId");
|
||
|
|
||
|
-- CreateIndex
|
||
|
CREATE UNIQUE INDEX "City_name_stateId_key" ON "City"("name", "stateId");
|
||
|
|
||
|
-- AddForeignKey
|
||
|
ALTER TABLE "State" ADD CONSTRAINT "State_countryId_fkey" FOREIGN KEY ("countryId") REFERENCES "Country"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||
|
|
||
|
-- AddForeignKey
|
||
|
ALTER TABLE "City" ADD CONSTRAINT "City_stateId_fkey" FOREIGN KEY ("stateId") REFERENCES "State"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|