-- CreateEnum
CREATE TYPE "ExternalServiceType" AS ENUM ('Twilio', 'Sendgrid', 'Finch', 'Sparrow', 'Solid', 'Liquid', 'VeryGoodSecurity');

-- CreateEnum
CREATE TYPE "FinancialAccountType" AS ENUM ('Checking', 'Savings');

-- CreateEnum
CREATE TYPE "CardType" AS ENUM ('PhysicalDebitCard', 'VirtualDebitCard', 'PhysicalCreditCard', 'VirtualCreditCard');

-- CreateEnum
CREATE TYPE "CardStatus" AS ENUM ('Pending', 'Active', 'Frozen', 'Canceled');

-- CreateEnum
CREATE TYPE "InviteAcceptance" AS ENUM ('Pending', 'Accepted', 'Rejected');

-- CreateEnum
CREATE TYPE "MemberRequestType" AS ENUM ('DirectDepositChange');

-- CreateEnum
CREATE TYPE "MemberRequestStatus" AS ENUM ('Approved');

-- CreateEnum
CREATE TYPE "PerkType" AS ENUM ('Reference', 'Message', 'Badge', 'EarnedWageAccess');

-- CreateEnum
CREATE TYPE "PerkInstanceStatus" AS ENUM ('Pending', 'Active', 'Complete');

-- CreateEnum
CREATE TYPE "ChannelNotificationType" AS ENUM ('SMS', 'Email');

-- CreateEnum
CREATE TYPE "ChannelNotificationStatus" AS ENUM ('Created', 'Sent', 'Error', 'Received', 'Read', 'Clicked');

-- CreateEnum
CREATE TYPE "UserModelName" AS ENUM ('User');

-- CreateEnum
CREATE TYPE "AddressModelName" AS ENUM ('Address');

-- CreateEnum
CREATE TYPE "SessionModelName" AS ENUM ('Session');

-- CreateEnum
CREATE TYPE "ActivityModelName" AS ENUM ('Activity');

-- CreateEnum
CREATE TYPE "FinancialAccountModelName" AS ENUM ('FinancialAccount');

-- CreateEnum
CREATE TYPE "CardModelName" AS ENUM ('Card');

-- CreateEnum
CREATE TYPE "FinancialAccountAccessRoleModelName" AS ENUM ('FinancialAccountAccessRole');

-- CreateEnum
CREATE TYPE "FinancialAccountAccessModelName" AS ENUM ('FinancialAccountAccess');

-- CreateEnum
CREATE TYPE "OrganizationModelName" AS ENUM ('Organization');

-- CreateEnum
CREATE TYPE "MemberModelName" AS ENUM ('Member');

-- CreateEnum
CREATE TYPE "InviteModelName" AS ENUM ('Invite');

-- CreateEnum
CREATE TYPE "MemberRequestModelName" AS ENUM ('MemberRequest');

-- CreateEnum
CREATE TYPE "MemberGroupModelName" AS ENUM ('MemberGroup');

-- CreateEnum
CREATE TYPE "MemberRoleModelName" AS ENUM ('MemberRole');

-- CreateEnum
CREATE TYPE "TagTypeModelName" AS ENUM ('TagType');

-- CreateEnum
CREATE TYPE "TagModelName" AS ENUM ('Tag');

-- CreateEnum
CREATE TYPE "MemberTagModelName" AS ENUM ('MemberTag');

-- CreateEnum
CREATE TYPE "PayrollProviderModelName" AS ENUM ('PayrollProvider');

-- CreateEnum
CREATE TYPE "PerkTemplateModelName" AS ENUM ('PerkTemplate');

-- CreateEnum
CREATE TYPE "PerkDefinitionModelName" AS ENUM ('PerkDefinition');

-- CreateEnum
CREATE TYPE "PerkInstanceModelName" AS ENUM ('PerkInstance');

-- CreateEnum
CREATE TYPE "PerkEventModelName" AS ENUM ('PerkEvent');

-- CreateEnum
CREATE TYPE "NotificationModelName" AS ENUM ('Notification');

-- CreateEnum
CREATE TYPE "ChannelNotificationModelName" AS ENUM ('ChannelNotification');

-- CreateTable
CREATE TABLE "User" (
    "modelName" "UserModelName" NOT NULL DEFAULT E'User',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "dateOfBirth" TIMESTAMP(3),
    "email" TEXT NOT NULL DEFAULT E'',
    "isEmailVerified" BOOLEAN NOT NULL DEFAULT false,
    "hashedEmailVerificationToken" TEXT NOT NULL DEFAULT E'',
    "emailVerificationTokenExpiresAt" TIMESTAMP(3),
    "phone" TEXT NOT NULL DEFAULT E'',
    "isPhoneVerified" BOOLEAN NOT NULL DEFAULT false,
    "hashedPassword" TEXT NOT NULL DEFAULT E'',
    "hashedPasswordResetToken" TEXT NOT NULL DEFAULT E'',
    "passwordResetTokenExpiresAt" TIMESTAMP(3),
    "isAgreedToTerms" BOOLEAN NOT NULL DEFAULT false,
    "isConsumerBankingEnabled" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',
    "firstName" TEXT NOT NULL,
    "middleName" TEXT NOT NULL DEFAULT E'',
    "lastName" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "User_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Address" (
    "modelName" "AddressModelName" NOT NULL DEFAULT E'Address',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "isPhysical" BOOLEAN NOT NULL,
    "isMailing" BOOLEAN NOT NULL,
    "line1" TEXT NOT NULL,
    "line2" TEXT NOT NULL DEFAULT E'',
    "city" TEXT NOT NULL,
    "region" TEXT NOT NULL,
    "postalCode" TEXT NOT NULL,
    "country" TEXT NOT NULL DEFAULT E'US',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "userId" UUID NOT NULL,

    CONSTRAINT "Address_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Session" (
    "modelName" "SessionModelName" NOT NULL DEFAULT E'Session',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "sid" TEXT NOT NULL,
    "data" JSONB NOT NULL,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "userId" UUID,

    CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Activity" (
    "modelName" "ActivityModelName" NOT NULL DEFAULT E'Activity',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "objectId" TEXT NOT NULL,
    "objectModel" TEXT NOT NULL,
    "data" JSONB NOT NULL DEFAULT '{}',
    "userId" UUID,
    "organizationId" UUID,
    "financialAccountId" UUID,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Activity_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FinancialAccount" (
    "modelName" "FinancialAccountModelName" NOT NULL DEFAULT E'FinancialAccount',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "displayName" TEXT NOT NULL DEFAULT E'',
    "type" "FinancialAccountType" NOT NULL,
    "last4" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "FinancialAccount_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Card" (
    "modelName" "CardModelName" NOT NULL DEFAULT E'Card',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "type" "CardType" NOT NULL,
    "status" "CardStatus" NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "last4" TEXT NOT NULL,
    "cardholderName" TEXT NOT NULL,
    "expiryMonth" TEXT NOT NULL,
    "expiryYear" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',
    "financialAccountId" UUID NOT NULL,

    CONSTRAINT "Card_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FinancialAccountAccessRole" (
    "modelName" "FinancialAccountAccessRoleModelName" NOT NULL DEFAULT E'FinancialAccountAccessRole',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "permissions" JSONB NOT NULL DEFAULT '{}',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "FinancialAccountAccessRole_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "FinancialAccountAccess" (
    "modelName" "FinancialAccountAccessModelName" NOT NULL DEFAULT E'FinancialAccountAccess',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "isOwner" BOOLEAN NOT NULL,
    "roleId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "userId" UUID NOT NULL,
    "financialAccountId" UUID NOT NULL,

    CONSTRAINT "FinancialAccountAccess_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Organization" (
    "modelName" "OrganizationModelName" NOT NULL DEFAULT E'Organization',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "logoUrl" TEXT NOT NULL DEFAULT E'',
    "isSuperuser" BOOLEAN NOT NULL DEFAULT false,
    "isGlobal" BOOLEAN NOT NULL DEFAULT false,
    "ownerId" UUID,
    "requestEmails" TEXT NOT NULL DEFAULT E'',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "Organization_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Member" (
    "modelName" "MemberModelName" NOT NULL DEFAULT E'Member',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "email" TEXT NOT NULL DEFAULT E'',
    "phone" TEXT NOT NULL DEFAULT E'',
    "startAt" TIMESTAMP(3) NOT NULL,
    "endAt" TIMESTAMP(3),
    "userId" UUID,
    "isParticipant" BOOLEAN NOT NULL DEFAULT false,
    "roleId" UUID,
    "payrollProviderId" UUID,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',
    "firstName" TEXT NOT NULL,
    "middleName" TEXT NOT NULL DEFAULT E'',
    "lastName" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "Member_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Invite" (
    "modelName" "InviteModelName" NOT NULL DEFAULT E'Invite',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "text" TEXT NOT NULL DEFAULT E'',
    "acceptance" "InviteAcceptance" NOT NULL DEFAULT E'Pending',
    "memberId" UUID NOT NULL,
    "notificationId" UUID,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,

    CONSTRAINT "Invite_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MemberRequest" (
    "modelName" "MemberRequestModelName" NOT NULL DEFAULT E'MemberRequest',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "type" "MemberRequestType" NOT NULL,
    "status" "MemberRequestStatus" NOT NULL,
    "data" JSONB NOT NULL,
    "memberId" UUID NOT NULL,
    "financialAccountId" UUID,
    "notificationId" UUID,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "userId" UUID NOT NULL,

    CONSTRAINT "MemberRequest_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MemberGroup" (
    "modelName" "MemberGroupModelName" NOT NULL DEFAULT E'MemberGroup',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "criteria" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "organizationId" UUID NOT NULL,

    CONSTRAINT "MemberGroup_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MemberRole" (
    "modelName" "MemberRoleModelName" NOT NULL DEFAULT E'MemberRole',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "permissions" JSONB NOT NULL DEFAULT '{}',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "organizationId" UUID NOT NULL,

    CONSTRAINT "MemberRole_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "TagType" (
    "modelName" "TagTypeModelName" NOT NULL DEFAULT E'TagType',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',
    "externalServiceReference" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "TagType_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tag" (
    "modelName" "TagModelName" NOT NULL DEFAULT E'Tag',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "tagTypeId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',
    "externalServiceReference" TEXT NOT NULL DEFAULT E'',
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "Tag_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "MemberTag" (
    "modelName" "MemberTagModelName" NOT NULL DEFAULT E'MemberTag',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "memberId" UUID NOT NULL,
    "tagId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,

    CONSTRAINT "MemberTag_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PayrollProvider" (
    "modelName" "PayrollProviderModelName" NOT NULL DEFAULT E'PayrollProvider',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "token" TEXT NOT NULL DEFAULT E'',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "organizationId" UUID NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "PayrollProvider_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PerkTemplate" (
    "modelName" "PerkTemplateModelName" NOT NULL DEFAULT E'PerkTemplate',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "referenceId" UUID,
    "description" TEXT NOT NULL DEFAULT E'',
    "type" "PerkType" NOT NULL,
    "settings" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',
    "organizationId" UUID NOT NULL,

    CONSTRAINT "PerkTemplate_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PerkDefinition" (
    "modelName" "PerkDefinitionModelName" NOT NULL DEFAULT E'PerkDefinition',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "perkTemplateId" UUID NOT NULL,
    "type" "PerkType" NOT NULL,
    "settings" JSONB NOT NULL,
    "criteria" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "displayName" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "PerkDefinition_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PerkInstance" (
    "modelName" "PerkInstanceModelName" NOT NULL DEFAULT E'PerkInstance',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "status" "PerkInstanceStatus" NOT NULL,
    "type" "PerkType" NOT NULL,
    "settings" JSONB NOT NULL,
    "memberId" UUID NOT NULL,
    "perkDefinitionId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "userId" UUID NOT NULL,

    CONSTRAINT "PerkInstance_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PerkEvent" (
    "modelName" "PerkEventModelName" NOT NULL DEFAULT E'PerkEvent',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "perkInstanceId" UUID NOT NULL,
    "data" JSONB NOT NULL DEFAULT '{}',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,
    "organizationId" UUID NOT NULL,
    "userId" UUID NOT NULL,

    CONSTRAINT "PerkEvent_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Notification" (
    "modelName" "NotificationModelName" NOT NULL DEFAULT E'Notification',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "isRead" BOOLEAN NOT NULL DEFAULT false,
    "userId" UUID,
    "organizationId" UUID,
    "unsecureSubject" TEXT NOT NULL,
    "unsecureText" TEXT NOT NULL,
    "unsecureHtml" TEXT NOT NULL,
    "secureText" TEXT NOT NULL,
    "secureHtml" TEXT NOT NULL,
    "actionUrl" TEXT NOT NULL DEFAULT E'',
    "action" TEXT NOT NULL DEFAULT E'',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "isHidden" BOOLEAN NOT NULL DEFAULT false,

    CONSTRAINT "Notification_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "ChannelNotification" (
    "modelName" "ChannelNotificationModelName" NOT NULL DEFAULT E'ChannelNotification',
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "type" "ChannelNotificationType" NOT NULL,
    "status" "ChannelNotificationStatus" NOT NULL,
    "toPhone" TEXT NOT NULL DEFAULT E'',
    "fromPhone" TEXT NOT NULL DEFAULT E'',
    "toEmail" TEXT NOT NULL DEFAULT E'',
    "fromEmail" TEXT NOT NULL DEFAULT E'',
    "notificationId" UUID NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "externalServiceType" "ExternalServiceType",
    "externalServiceId" TEXT NOT NULL DEFAULT E'',

    CONSTRAINT "ChannelNotification_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "TestEntity" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "data" JSONB NOT NULL,

    CONSTRAINT "TestEntity_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Session_sid_key" ON "Session"("sid");

-- CreateIndex
CREATE UNIQUE INDEX "Organization_ownerId_key" ON "Organization"("ownerId");

-- AddForeignKey
ALTER TABLE "Address" ADD CONSTRAINT "Address_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_financialAccountId_fkey" FOREIGN KEY ("financialAccountId") REFERENCES "FinancialAccount"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Activity" ADD CONSTRAINT "Activity_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Card" ADD CONSTRAINT "Card_financialAccountId_fkey" FOREIGN KEY ("financialAccountId") REFERENCES "FinancialAccount"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FinancialAccountAccess" ADD CONSTRAINT "FinancialAccountAccess_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FinancialAccountAccess" ADD CONSTRAINT "FinancialAccountAccess_financialAccountId_fkey" FOREIGN KEY ("financialAccountId") REFERENCES "FinancialAccount"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "FinancialAccountAccess" ADD CONSTRAINT "FinancialAccountAccess_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "FinancialAccountAccessRole"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Organization" ADD CONSTRAINT "Organization_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "Member"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Member" ADD CONSTRAINT "Member_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Member" ADD CONSTRAINT "Member_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Member" ADD CONSTRAINT "Member_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "MemberRole"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Member" ADD CONSTRAINT "Member_payrollProviderId_fkey" FOREIGN KEY ("payrollProviderId") REFERENCES "PayrollProvider"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Invite" ADD CONSTRAINT "Invite_notificationId_fkey" FOREIGN KEY ("notificationId") REFERENCES "Notification"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRequest" ADD CONSTRAINT "MemberRequest_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRequest" ADD CONSTRAINT "MemberRequest_financialAccountId_fkey" FOREIGN KEY ("financialAccountId") REFERENCES "FinancialAccount"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRequest" ADD CONSTRAINT "MemberRequest_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRequest" ADD CONSTRAINT "MemberRequest_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRequest" ADD CONSTRAINT "MemberRequest_notificationId_fkey" FOREIGN KEY ("notificationId") REFERENCES "Notification"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberGroup" ADD CONSTRAINT "MemberGroup_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberRole" ADD CONSTRAINT "MemberRole_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TagType" ADD CONSTRAINT "TagType_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tag" ADD CONSTRAINT "Tag_tagTypeId_fkey" FOREIGN KEY ("tagTypeId") REFERENCES "TagType"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberTag" ADD CONSTRAINT "MemberTag_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberTag" ADD CONSTRAINT "MemberTag_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MemberTag" ADD CONSTRAINT "MemberTag_tagId_fkey" FOREIGN KEY ("tagId") REFERENCES "Tag"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PayrollProvider" ADD CONSTRAINT "PayrollProvider_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkTemplate" ADD CONSTRAINT "PerkTemplate_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkTemplate" ADD CONSTRAINT "PerkTemplate_referenceId_fkey" FOREIGN KEY ("referenceId") REFERENCES "PerkTemplate"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkDefinition" ADD CONSTRAINT "PerkDefinition_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkDefinition" ADD CONSTRAINT "PerkDefinition_perkTemplateId_fkey" FOREIGN KEY ("perkTemplateId") REFERENCES "PerkTemplate"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkInstance" ADD CONSTRAINT "PerkInstance_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkInstance" ADD CONSTRAINT "PerkInstance_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkInstance" ADD CONSTRAINT "PerkInstance_memberId_fkey" FOREIGN KEY ("memberId") REFERENCES "Member"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkInstance" ADD CONSTRAINT "PerkInstance_perkDefinitionId_fkey" FOREIGN KEY ("perkDefinitionId") REFERENCES "PerkDefinition"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkEvent" ADD CONSTRAINT "PerkEvent_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkEvent" ADD CONSTRAINT "PerkEvent_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PerkEvent" ADD CONSTRAINT "PerkEvent_perkInstanceId_fkey" FOREIGN KEY ("perkInstanceId") REFERENCES "PerkInstance"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Notification" ADD CONSTRAINT "Notification_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ChannelNotification" ADD CONSTRAINT "ChannelNotification_notificationId_fkey" FOREIGN KEY ("notificationId") REFERENCES "Notification"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
