CREATE TABLE IF NOT EXISTS "businesses" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid,
	"type" integer,
	"title" varchar(255),
	"description" text,
	"city" varchar(255),
	"state" char(2),
	"price" double precision,
	"favoritesForUser" varchar(30)[],
	"draft" boolean,
	"listingsCategory" varchar(255),
	"realEstateIncluded" boolean,
	"leasedLocation" boolean,
	"franchiseResale" boolean,
	"salesRevenue" double precision,
	"cashFlow" double precision,
	"supportAndTraining" text,
	"employees" integer,
	"established" integer,
	"internalListingNumber" integer,
	"reasonForSale" varchar(255),
	"brokerLicencing" varchar(255),
	"internals" text,
	"created" timestamp,
	"updated" timestamp,
	"visits" integer,
	"lastVisit" timestamp
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "commercials" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"userId" uuid,
	"type" integer,
	"title" varchar(255),
	"description" text,
	"city" varchar(255),
	"state" char(2),
	"price" double precision,
	"favoritesForUser" varchar(30)[],
	"hideImage" boolean,
	"draft" boolean,
	"zipCode" integer,
	"county" varchar(255),
	"email" varchar(255),
	"website" varchar(255),
	"phoneNumber" varchar(255),
	"imageOrder" varchar(30)[],
	"imagePath" varchar(50),
	"created" timestamp,
	"updated" timestamp,
	"visits" integer,
	"lastVisit" timestamp
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
	"firstname" varchar(255) NOT NULL,
	"lastname" varchar(255) NOT NULL,
	"email" varchar(255) NOT NULL,
	"phoneNumber" varchar(255),
	"description" text,
	"companyName" varchar(255),
	"companyOverview" text,
	"companyWebsite" varchar(255),
	"companyLocation" varchar(255),
	"offeredServices" text,
	"areasServed" varchar(100)[],
	"hasProfile" boolean,
	"hasCompanyLogo" boolean,
	"licensedIn" varchar(50)[]
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "businesses" ADD CONSTRAINT "businesses_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "commercials" ADD CONSTRAINT "commercials_userId_users_id_fk" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
