Skip to content

Commit

Permalink
add "IF NOT EXISTS" to index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Feb 9, 2024
1 parent 7b3ac17 commit 1278373
Showing 1 changed file with 139 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*
Warnings:
Warnings:
- You are about to drop the column `orgLocationId` on the `OrgSocialMedia` table. All the data in the column will be lost.
- You are about to drop the column `orgLocationId` on the `OrgWebsite` table. All the data in the column will be lost.
*/
- You are about to drop the column `orgLocationId` on the `OrgSocialMedia` table. All the data in the column will be lost.
- You are about to drop the column `orgLocationId` on the `OrgWebsite` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "OrgSocialMedia" DROP CONSTRAINT "OrgSocialMedia_orgLocationId_fkey";
ALTER TABLE "OrgSocialMedia"
DROP CONSTRAINT "OrgSocialMedia_orgLocationId_fkey";

-- DropForeignKey
ALTER TABLE "OrgWebsite" DROP CONSTRAINT "OrgWebsite_orgLocationId_fkey";
ALTER TABLE "OrgWebsite"
DROP CONSTRAINT "OrgWebsite_orgLocationId_fkey";

-- DropIndex
DROP INDEX "OrgLocation_deleted_idx";
Expand All @@ -30,184 +31,243 @@ DROP INDEX "OrgSocialMedia_orgLocationId_idx";
DROP INDEX "OrgWebsite_orgLocationId_idx";

-- AlterTable
ALTER TABLE "OrgSocialMedia" DROP COLUMN "orgLocationId";
ALTER TABLE "OrgSocialMedia"
DROP COLUMN "orgLocationId";

-- AlterTable
ALTER TABLE "OrgWebsite" DROP COLUMN "orgLocationId";
ALTER TABLE "OrgWebsite"
DROP COLUMN "orgLocationId";

-- CreateTable
CREATE TABLE "OrgServiceWebsite" (
"orgWebsiteId" TEXT NOT NULL,
"serviceId" TEXT NOT NULL,
"linkedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" BOOLEAN NOT NULL DEFAULT true,

CONSTRAINT "OrgServiceWebsite_pkey" PRIMARY KEY ("orgWebsiteId","serviceId")
CREATE TABLE "OrgServiceWebsite"(
"orgWebsiteId" text NOT NULL,
"serviceId" text NOT NULL,
"linkedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" boolean NOT NULL DEFAULT TRUE,
CONSTRAINT "OrgServiceWebsite_pkey" PRIMARY KEY ("orgWebsiteId", "serviceId")
);

-- CreateTable
CREATE TABLE "OrgLocationWebsite" (
"orgLocationId" TEXT NOT NULL,
"orgWebsiteId" TEXT NOT NULL,
"linkedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" BOOLEAN NOT NULL DEFAULT true,

CONSTRAINT "OrgLocationWebsite_pkey" PRIMARY KEY ("orgLocationId","orgWebsiteId")
CREATE TABLE "OrgLocationWebsite"(
"orgLocationId" text NOT NULL,
"orgWebsiteId" text NOT NULL,
"linkedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" boolean NOT NULL DEFAULT TRUE,
CONSTRAINT "OrgLocationWebsite_pkey" PRIMARY KEY ("orgLocationId", "orgWebsiteId")
);

-- CreateTable
CREATE TABLE "OrgLocationSocialMedia" (
"orgLocationId" TEXT NOT NULL,
"socialMediaId" TEXT NOT NULL,
"linkedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" BOOLEAN NOT NULL DEFAULT true,

CONSTRAINT "OrgLocationSocialMedia_pkey" PRIMARY KEY ("orgLocationId","socialMediaId")
CREATE TABLE "OrgLocationSocialMedia"(
"orgLocationId" text NOT NULL,
"socialMediaId" text NOT NULL,
"linkedAt" timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"active" boolean NOT NULL DEFAULT TRUE,
CONSTRAINT "OrgLocationSocialMedia_pkey" PRIMARY KEY ("orgLocationId", "socialMediaId")
);

-- CreateIndex
CREATE INDEX "OrgServiceWebsite_serviceId_orgWebsiteId_idx" ON "OrgServiceWebsite"("serviceId", "orgWebsiteId");
CREATE INDEX IF NOT EXISTS "OrgServiceWebsite_serviceId_orgWebsiteId_idx" ON
"OrgServiceWebsite"("serviceId", "orgWebsiteId");

-- CreateIndex
CREATE INDEX "OrgLocationWebsite_orgWebsiteId_orgLocationId_idx" ON "OrgLocationWebsite"("orgWebsiteId", "orgLocationId");
CREATE INDEX IF NOT EXISTS "OrgLocationWebsite_orgWebsiteId_orgLocationId_idx"
ON "OrgLocationWebsite"("orgWebsiteId", "orgLocationId");

-- CreateIndex
CREATE INDEX "OrgLocationSocialMedia_socialMediaId_orgLocationId_idx" ON "OrgLocationSocialMedia"("socialMediaId", "orgLocationId");
CREATE INDEX IF NOT EXISTS
"OrgLocationSocialMedia_socialMediaId_orgLocationId_idx" ON
"OrgLocationSocialMedia"("socialMediaId", "orgLocationId");

-- CreateIndex
CREATE INDEX "AssignedRole_roleId_userId_idx" ON "AssignedRole"("roleId", "userId");
CREATE INDEX IF NOT EXISTS "AssignedRole_roleId_userId_idx" ON
"AssignedRole"("roleId", "userId");

-- CreateIndex
CREATE INDEX "AttributeSupplement_active_attributeId_idx" ON "AttributeSupplement"("active", "attributeId");
CREATE INDEX IF NOT EXISTS "AttributeSupplement_active_attributeId_idx" ON
"AttributeSupplement"("active", "attributeId");

-- CreateIndex
CREATE INDEX "FreeText_ns_key_idx" ON "FreeText"("ns", "key");
CREATE INDEX IF NOT EXISTS "FreeText_ns_key_idx" ON "FreeText"("ns", "key");

-- CreateIndex
CREATE INDEX "ListSharedWith_listId_userId_idx" ON "ListSharedWith"("listId", "userId");
CREATE INDEX IF NOT EXISTS "ListSharedWith_listId_userId_idx" ON
"ListSharedWith"("listId", "userId");

-- CreateIndex
CREATE INDEX "LocationPermission_orgLocationId_userId_idx" ON "LocationPermission"("orgLocationId", "userId");
CREATE INDEX IF NOT EXISTS "LocationPermission_orgLocationId_userId_idx" ON
"LocationPermission"("orgLocationId", "userId");

-- CreateIndex
CREATE INDEX "LocationPermission_userId_orgLocationId_idx" ON "LocationPermission"("userId", "orgLocationId");
CREATE INDEX IF NOT EXISTS "LocationPermission_userId_orgLocationId_idx" ON
"LocationPermission"("userId", "orgLocationId");

-- CreateIndex
CREATE INDEX "OrgEmail_id_published_deleted_idx" ON "OrgEmail"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgEmail_id_published_deleted_idx" ON
"OrgEmail"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgHours_id_active_idx" ON "OrgHours"("id", "active");
CREATE INDEX IF NOT EXISTS "OrgHours_id_active_idx" ON "OrgHours"("id", "active");

-- CreateIndex
CREATE INDEX "OrgLocation_id_published_deleted_idx" ON "OrgLocation"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgLocation_id_published_deleted_idx" ON
"OrgLocation"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgLocationEmail_orgLocationId_orgEmailId_idx" ON "OrgLocationEmail"("orgLocationId", "orgEmailId");
CREATE INDEX IF NOT EXISTS "OrgLocationEmail_orgLocationId_orgEmailId_idx" ON
"OrgLocationEmail"("orgLocationId", "orgEmailId");

-- CreateIndex
CREATE INDEX "OrgLocationPhone_phoneId_orgLocationId_idx" ON "OrgLocationPhone"("phoneId", "orgLocationId");
CREATE INDEX IF NOT EXISTS "OrgLocationPhone_phoneId_orgLocationId_idx" ON
"OrgLocationPhone"("phoneId", "orgLocationId");

-- CreateIndex
CREATE INDEX "OrgLocationService_active_serviceId_idx" ON "OrgLocationService"("active", "serviceId");
CREATE INDEX IF NOT EXISTS "OrgLocationService_active_serviceId_idx" ON
"OrgLocationService"("active", "serviceId");

-- CreateIndex
CREATE INDEX "OrgPhone_id_published_deleted_idx" ON "OrgPhone"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgPhone_id_published_deleted_idx" ON
"OrgPhone"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgPhoneLanguage_languageId_orgPhoneId_idx" ON "OrgPhoneLanguage"("languageId", "orgPhoneId");
CREATE INDEX IF NOT EXISTS "OrgPhoneLanguage_languageId_orgPhoneId_idx" ON
"OrgPhoneLanguage"("languageId", "orgPhoneId");

-- CreateIndex
CREATE INDEX "OrgPhoto_id_published_deleted_idx" ON "OrgPhoto"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgPhoto_id_published_deleted_idx" ON
"OrgPhoto"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgService_organizationId_published_deleted_idx" ON "OrgService"("organizationId", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgService_organizationId_published_deleted_idx" ON
"OrgService"("organizationId", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgService_id_published_deleted_idx" ON "OrgService"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgService_id_published_deleted_idx" ON
"OrgService"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgServiceEmail_serviceId_orgEmailId_idx" ON "OrgServiceEmail"("serviceId", "orgEmailId");
CREATE INDEX IF NOT EXISTS "OrgServiceEmail_serviceId_orgEmailId_idx" ON
"OrgServiceEmail"("serviceId", "orgEmailId");

-- CreateIndex
CREATE INDEX "OrgServicePhone_serviceId_orgPhoneId_idx" ON "OrgServicePhone"("serviceId", "orgPhoneId");
CREATE INDEX IF NOT EXISTS "OrgServicePhone_serviceId_orgPhoneId_idx" ON
"OrgServicePhone"("serviceId", "orgPhoneId");

-- CreateIndex
CREATE INDEX "OrgSocialMedia_id_published_deleted_idx" ON "OrgSocialMedia"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgSocialMedia_id_published_deleted_idx" ON
"OrgSocialMedia"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgWebsite_id_published_deleted_idx" ON "OrgWebsite"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "OrgWebsite_id_published_deleted_idx" ON
"OrgWebsite"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrgWebsiteLanguage_languageId_orgWebsiteId_idx" ON "OrgWebsiteLanguage"("languageId", "orgWebsiteId");
CREATE INDEX IF NOT EXISTS "OrgWebsiteLanguage_languageId_orgWebsiteId_idx" ON
"OrgWebsiteLanguage"("languageId", "orgWebsiteId");

-- CreateIndex
CREATE INDEX "Organization_slug_published_deleted_idx" ON "Organization"("slug", "published", "deleted");
CREATE INDEX IF NOT EXISTS "Organization_slug_published_deleted_idx" ON
"Organization"("slug", "published", "deleted");

-- CreateIndex
CREATE INDEX "Organization_id_published_deleted_idx" ON "Organization"("id", "published" DESC, "deleted");
CREATE INDEX IF NOT EXISTS "Organization_id_published_deleted_idx" ON
"Organization"("id", "published" DESC, "deleted");

-- CreateIndex
CREATE INDEX "OrganizationEmail_organizationId_orgEmailId_idx" ON "OrganizationEmail"("organizationId", "orgEmailId");
CREATE INDEX IF NOT EXISTS "OrganizationEmail_organizationId_orgEmailId_idx" ON
"OrganizationEmail"("organizationId", "orgEmailId");

-- CreateIndex
CREATE INDEX "OrganizationPermission_organizationId_userId_idx" ON "OrganizationPermission"("organizationId", "userId");
CREATE INDEX IF NOT EXISTS "OrganizationPermission_organizationId_userId_idx"
ON "OrganizationPermission"("organizationId", "userId");

-- CreateIndex
CREATE INDEX "OrganizationPermission_userId_organizationId_idx" ON "OrganizationPermission"("userId", "organizationId");
CREATE INDEX IF NOT EXISTS "OrganizationPermission_userId_organizationId_idx"
ON "OrganizationPermission"("userId", "organizationId");

-- CreateIndex
CREATE INDEX "OrganizationPhone_phoneId_organizationId_idx" ON "OrganizationPhone"("phoneId", "organizationId");
CREATE INDEX IF NOT EXISTS "OrganizationPhone_phoneId_organizationId_idx" ON
"OrganizationPhone"("phoneId", "organizationId");

-- CreateIndex
CREATE INDEX "RolePermission_permissionId_roleId_idx" ON "RolePermission"("permissionId", "roleId");
CREATE INDEX IF NOT EXISTS "RolePermission_permissionId_roleId_idx" ON
"RolePermission"("permissionId", "roleId");

-- CreateIndex
CREATE INDEX "SavedOrganization_organizationId_listId_idx" ON "SavedOrganization"("organizationId", "listId");
CREATE INDEX IF NOT EXISTS "SavedOrganization_organizationId_listId_idx" ON
"SavedOrganization"("organizationId", "listId");

-- CreateIndex
CREATE INDEX "SavedService_serviceId_listId_idx" ON "SavedService"("serviceId", "listId");
CREATE INDEX IF NOT EXISTS "SavedService_serviceId_listId_idx" ON
"SavedService"("serviceId", "listId");

-- CreateIndex
CREATE INDEX "ServiceArea_active_organizationId_idx" ON "ServiceArea"("active", "organizationId");
CREATE INDEX IF NOT EXISTS "ServiceArea_active_organizationId_idx" ON
"ServiceArea"("active", "organizationId");

-- CreateIndex
CREATE INDEX "ServiceArea_active_orgLocationId_idx" ON "ServiceArea"("active", "orgLocationId");
CREATE INDEX IF NOT EXISTS "ServiceArea_active_orgLocationId_idx" ON
"ServiceArea"("active", "orgLocationId");

-- CreateIndex
CREATE INDEX "ServiceArea_active_orgServiceId_idx" ON "ServiceArea"("active", "orgServiceId");
CREATE INDEX IF NOT EXISTS "ServiceArea_active_orgServiceId_idx" ON
"ServiceArea"("active", "orgServiceId");

-- CreateIndex
CREATE INDEX "ServiceAreaCountry_active_serviceAreaId_idx" ON "ServiceAreaCountry"("active", "serviceAreaId");
CREATE INDEX IF NOT EXISTS "ServiceAreaCountry_active_serviceAreaId_idx" ON
"ServiceAreaCountry"("active", "serviceAreaId");

-- CreateIndex
CREATE INDEX "ServiceAreaDist_active_serviceAreaId_idx" ON "ServiceAreaDist"("active", "serviceAreaId");
CREATE INDEX IF NOT EXISTS "ServiceAreaDist_active_serviceAreaId_idx" ON
"ServiceAreaDist"("active", "serviceAreaId");

-- CreateIndex
CREATE INDEX "ServiceTagToCategory_serviceTagId_categoryId_idx" ON "ServiceTagToCategory"("serviceTagId", "categoryId");
CREATE INDEX IF NOT EXISTS "ServiceTagToCategory_serviceTagId_categoryId_idx"
ON "ServiceTagToCategory"("serviceTagId", "categoryId");

-- CreateIndex
CREATE INDEX "UserMail_fromUserId_toUserId_idx" ON "UserMail"("fromUserId", "toUserId");
CREATE INDEX IF NOT EXISTS "UserMail_fromUserId_toUserId_idx" ON
"UserMail"("fromUserId", "toUserId");

-- CreateIndex
CREATE INDEX "UserPermission_permissionId_userId_idx" ON "UserPermission"("permissionId", "userId");
CREATE INDEX IF NOT EXISTS "UserPermission_permissionId_userId_idx" ON
"UserPermission"("permissionId", "userId");

-- CreateIndex
CREATE INDEX "UserToOrganization_organizationId_userId_idx" ON "UserToOrganization"("organizationId", "userId");
CREATE INDEX IF NOT EXISTS "UserToOrganization_organizationId_userId_idx" ON
"UserToOrganization"("organizationId", "userId");

-- AddForeignKey
ALTER TABLE "OrgServiceWebsite" ADD CONSTRAINT "OrgServiceWebsite_orgWebsiteId_fkey" FOREIGN KEY ("orgWebsiteId") REFERENCES "OrgWebsite"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgServiceWebsite"
ADD CONSTRAINT "OrgServiceWebsite_orgWebsiteId_fkey" FOREIGN KEY
("orgWebsiteId") REFERENCES "OrgWebsite"("id") ON DELETE CASCADE ON
UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OrgServiceWebsite" ADD CONSTRAINT "OrgServiceWebsite_serviceId_fkey" FOREIGN KEY ("serviceId") REFERENCES "OrgService"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgServiceWebsite"
ADD CONSTRAINT "OrgServiceWebsite_serviceId_fkey" FOREIGN KEY
("serviceId") REFERENCES "OrgService"("id") ON DELETE CASCADE ON UPDATE
CASCADE;

-- AddForeignKey
ALTER TABLE "OrgLocationWebsite" ADD CONSTRAINT "OrgLocationWebsite_orgLocationId_fkey" FOREIGN KEY ("orgLocationId") REFERENCES "OrgLocation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgLocationWebsite"
ADD CONSTRAINT "OrgLocationWebsite_orgLocationId_fkey" FOREIGN KEY
("orgLocationId") REFERENCES "OrgLocation"("id") ON DELETE CASCADE ON
UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OrgLocationWebsite" ADD CONSTRAINT "OrgLocationWebsite_orgWebsiteId_fkey" FOREIGN KEY ("orgWebsiteId") REFERENCES "OrgWebsite"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgLocationWebsite"
ADD CONSTRAINT "OrgLocationWebsite_orgWebsiteId_fkey" FOREIGN KEY
("orgWebsiteId") REFERENCES "OrgWebsite"("id") ON DELETE CASCADE ON
UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OrgLocationSocialMedia" ADD CONSTRAINT "OrgLocationSocialMedia_orgLocationId_fkey" FOREIGN KEY ("orgLocationId") REFERENCES "OrgLocation"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgLocationSocialMedia"
ADD CONSTRAINT "OrgLocationSocialMedia_orgLocationId_fkey" FOREIGN KEY
("orgLocationId") REFERENCES "OrgLocation"("id") ON DELETE CASCADE ON
UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "OrgLocationSocialMedia" ADD CONSTRAINT "OrgLocationSocialMedia_socialMediaId_fkey" FOREIGN KEY ("socialMediaId") REFERENCES "OrgSocialMedia"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "OrgLocationSocialMedia"
ADD CONSTRAINT "OrgLocationSocialMedia_socialMediaId_fkey" FOREIGN KEY
("socialMediaId") REFERENCES "OrgSocialMedia"("id") ON DELETE CASCADE
ON UPDATE CASCADE;

0 comments on commit 1278373

Please sign in to comment.