Lead Radar: исходный код
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
9749da5ae7
201 files changed
+97685
No files matched your search
@@ -0,0 +1,354 @@
|
||||
CREATE TABLE "admin_messages" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"text" text NOT NULL,
|
||||
"audience" text NOT NULL,
|
||||
"company_id" integer,
|
||||
"user_id" integer,
|
||||
"recipients" integer DEFAULT 0 NOT NULL,
|
||||
"sent_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "blacklist" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"phone" text NOT NULL,
|
||||
"added_by_id" integer,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "client_leads" (
|
||||
"client_id" integer NOT NULL,
|
||||
"lead_id" integer NOT NULL,
|
||||
"state" text DEFAULT 'offered' NOT NULL,
|
||||
"shown_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "clients" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"phone" text,
|
||||
"kind" text NOT NULL,
|
||||
"request" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"source" text,
|
||||
"assignee_id" integer NOT NULL,
|
||||
"status_id" integer NOT NULL,
|
||||
"reject_reason_id" integer,
|
||||
"next_action_at" timestamp with time zone,
|
||||
"next_action_note" text,
|
||||
"next_action_notified_at" timestamp with time zone,
|
||||
"status_changed_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "companies" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"plan" text NOT NULL,
|
||||
"billing_model" text DEFAULT 'fixed' NOT NULL,
|
||||
"planned_plan" text,
|
||||
"planned_billing_model" text,
|
||||
"planned_from" date,
|
||||
"subscription_ends_at" timestamp with time zone,
|
||||
"grace_days" integer DEFAULT 15 NOT NULL,
|
||||
"access_enabled" boolean DEFAULT false NOT NULL,
|
||||
"setup_fee_invoiced" boolean DEFAULT false NOT NULL,
|
||||
"settings" jsonb NOT NULL,
|
||||
"last_activity_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "deals" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"lead_id" integer,
|
||||
"client_id" integer,
|
||||
"agent_id" integer NOT NULL,
|
||||
"commission" numeric(14, 2) NOT NULL,
|
||||
"currency" text NOT NULL,
|
||||
"deal_date" date NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "email_tokens" (
|
||||
"token_hash" text PRIMARY KEY NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"expires_at" timestamp with time zone NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "events" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"lead_id" integer,
|
||||
"client_id" integer,
|
||||
"user_id" integer,
|
||||
"type" text NOT NULL,
|
||||
"old_value" text,
|
||||
"new_value" text,
|
||||
"text" text,
|
||||
"at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "filters" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"owner_user_id" integer,
|
||||
"name" text NOT NULL,
|
||||
"enabled" boolean DEFAULT true NOT NULL,
|
||||
"params" jsonb NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "invites" (
|
||||
"token" text PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"role" text DEFAULT 'agent' NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"revoked_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "invoices" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"period_start" date,
|
||||
"period_end" date,
|
||||
"amount" numeric(14, 2) NOT NULL,
|
||||
"currency" text DEFAULT 'USD' NOT NULL,
|
||||
"details" jsonb,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"paid_at" timestamp with time zone,
|
||||
"paid_method" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "lead_notifications" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"lead_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"chat_id" bigint,
|
||||
"message_id" integer,
|
||||
"has_photo" boolean DEFAULT false NOT NULL,
|
||||
"sent_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "leads" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"listing_id" integer,
|
||||
"source" text NOT NULL,
|
||||
"url" text,
|
||||
"title" text NOT NULL,
|
||||
"description" text,
|
||||
"deal_type" text,
|
||||
"property_type" text,
|
||||
"region" text,
|
||||
"district" text,
|
||||
"address" text,
|
||||
"price" numeric(14, 2),
|
||||
"currency" text,
|
||||
"rooms" integer,
|
||||
"area" numeric(10, 2),
|
||||
"floor" integer,
|
||||
"floors_total" integer,
|
||||
"photos" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"author_name" text,
|
||||
"phone" text,
|
||||
"assignee_id" integer,
|
||||
"status_id" integer NOT NULL,
|
||||
"reject_reason_id" integer,
|
||||
"next_action_at" timestamp with time zone,
|
||||
"next_action_note" text,
|
||||
"next_action_notified_at" timestamp with time zone,
|
||||
"taken_at" timestamp with time zone,
|
||||
"status_changed_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"pool_warned_at" timestamp with time zone,
|
||||
"previous_lead_id" integer,
|
||||
"created_by_id" integer,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "listings" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"external_id" text NOT NULL,
|
||||
"url" text NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"description" text,
|
||||
"deal_type" text,
|
||||
"property_type" text,
|
||||
"region" text,
|
||||
"district" text,
|
||||
"address" text,
|
||||
"price" numeric(14, 2),
|
||||
"currency" text,
|
||||
"rooms" integer,
|
||||
"area" numeric(10, 2),
|
||||
"floor" integer,
|
||||
"floors_total" integer,
|
||||
"photos" jsonb DEFAULT '[]'::jsonb NOT NULL,
|
||||
"author_name" text,
|
||||
"phone" text,
|
||||
"is_agency" boolean DEFAULT false NOT NULL,
|
||||
"published_at" timestamp with time zone,
|
||||
"active" boolean DEFAULT true NOT NULL,
|
||||
"removed_at" timestamp with time zone,
|
||||
"last_checked_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "outbox" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"kind" text NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"lead_id" integer,
|
||||
"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"attempts" integer DEFAULT 0 NOT NULL,
|
||||
"run_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"done_at" timestamp with time zone,
|
||||
"error" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "parser_runs" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"started_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"finished_at" timestamp with time zone,
|
||||
"status" text DEFAULT 'running' NOT NULL,
|
||||
"found_new" integer DEFAULT 0 NOT NULL,
|
||||
"errors" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "parser_state" (
|
||||
"category_id" integer PRIMARY KEY NOT NULL,
|
||||
"baseline_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "payments" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"invoice_id" integer NOT NULL,
|
||||
"provider" text NOT NULL,
|
||||
"external_id" text,
|
||||
"amount" numeric(14, 2) NOT NULL,
|
||||
"currency" text NOT NULL,
|
||||
"status" text NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "pipeline_statuses" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"pipeline" text NOT NULL,
|
||||
"code" text,
|
||||
"name" text NOT NULL,
|
||||
"position" integer NOT NULL,
|
||||
"pool_return" boolean DEFAULT false NOT NULL,
|
||||
"deleted_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "reject_reasons" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"pipeline" text NOT NULL,
|
||||
"code" text,
|
||||
"name" text NOT NULL,
|
||||
"position" integer NOT NULL,
|
||||
"deleted_at" timestamp with time zone
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "seen_listings" (
|
||||
"external_id" text PRIMARY KEY NOT NULL,
|
||||
"seen_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "sessions" (
|
||||
"token_hash" text PRIMARY KEY NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"acting_company_id" integer,
|
||||
"expires_at" timestamp with time zone NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "users" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer,
|
||||
"role" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"telegram_id" bigint,
|
||||
"telegram_username" text,
|
||||
"email" text,
|
||||
"email_verified_at" timestamp with time zone,
|
||||
"password_hash" text,
|
||||
"lang" text DEFAULT 'ru' NOT NULL,
|
||||
"quiet_from" text,
|
||||
"quiet_to" text,
|
||||
"notifications_paused" boolean DEFAULT false NOT NULL,
|
||||
"telegram_link_token" text,
|
||||
"removed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "admin_messages" ADD CONSTRAINT "admin_messages_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "admin_messages" ADD CONSTRAINT "admin_messages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "blacklist" ADD CONSTRAINT "blacklist_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "blacklist" ADD CONSTRAINT "blacklist_added_by_id_users_id_fk" FOREIGN KEY ("added_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_leads" ADD CONSTRAINT "client_leads_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_leads" ADD CONSTRAINT "client_leads_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD CONSTRAINT "clients_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD CONSTRAINT "clients_assignee_id_users_id_fk" FOREIGN KEY ("assignee_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD CONSTRAINT "clients_status_id_pipeline_statuses_id_fk" FOREIGN KEY ("status_id") REFERENCES "public"."pipeline_statuses"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD CONSTRAINT "clients_reject_reason_id_reject_reasons_id_fk" FOREIGN KEY ("reject_reason_id") REFERENCES "public"."reject_reasons"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_agent_id_users_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "email_tokens" ADD CONSTRAINT "email_tokens_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "events" ADD CONSTRAINT "events_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "events" ADD CONSTRAINT "events_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "events" ADD CONSTRAINT "events_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "events" ADD CONSTRAINT "events_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "filters" ADD CONSTRAINT "filters_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "filters" ADD CONSTRAINT "filters_owner_user_id_users_id_fk" FOREIGN KEY ("owner_user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "invites" ADD CONSTRAINT "invites_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "invites" ADD CONSTRAINT "invites_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "invoices" ADD CONSTRAINT "invoices_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_notifications" ADD CONSTRAINT "lead_notifications_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_notifications" ADD CONSTRAINT "lead_notifications_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_listing_id_listings_id_fk" FOREIGN KEY ("listing_id") REFERENCES "public"."listings"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_assignee_id_users_id_fk" FOREIGN KEY ("assignee_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_status_id_pipeline_statuses_id_fk" FOREIGN KEY ("status_id") REFERENCES "public"."pipeline_statuses"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_reject_reason_id_reject_reasons_id_fk" FOREIGN KEY ("reject_reason_id") REFERENCES "public"."reject_reasons"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "outbox" ADD CONSTRAINT "outbox_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "outbox" ADD CONSTRAINT "outbox_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "payments" ADD CONSTRAINT "payments_invoice_id_invoices_id_fk" FOREIGN KEY ("invoice_id") REFERENCES "public"."invoices"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "pipeline_statuses" ADD CONSTRAINT "pipeline_statuses_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "reject_reasons" ADD CONSTRAINT "reject_reasons_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "sessions" ADD CONSTRAINT "sessions_acting_company_id_companies_id_fk" FOREIGN KEY ("acting_company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "blacklist_uq" ON "blacklist" USING btree ("company_id","phone");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "client_leads_uq" ON "client_leads" USING btree ("client_id","lead_id");--> statement-breakpoint
|
||||
CREATE INDEX "clients_company_idx" ON "clients" USING btree ("company_id","status_id");--> statement-breakpoint
|
||||
CREATE INDEX "deals_company_date_idx" ON "deals" USING btree ("company_id","deal_date");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "deals_lead_uq" ON "deals" USING btree ("lead_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "deals_client_uq" ON "deals" USING btree ("client_id");--> statement-breakpoint
|
||||
CREATE INDEX "events_lead_idx" ON "events" USING btree ("lead_id");--> statement-breakpoint
|
||||
CREATE INDEX "events_client_idx" ON "events" USING btree ("client_id");--> statement-breakpoint
|
||||
CREATE INDEX "filters_company_idx" ON "filters" USING btree ("company_id");--> statement-breakpoint
|
||||
CREATE INDEX "invoices_company_idx" ON "invoices" USING btree ("company_id");--> statement-breakpoint
|
||||
CREATE INDEX "lead_notifications_lead_idx" ON "lead_notifications" USING btree ("lead_id");--> statement-breakpoint
|
||||
CREATE INDEX "leads_company_status_idx" ON "leads" USING btree ("company_id","status_id");--> statement-breakpoint
|
||||
CREATE INDEX "leads_company_assignee_idx" ON "leads" USING btree ("company_id","assignee_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "leads_company_listing_uq" ON "leads" USING btree ("company_id","listing_id") WHERE "leads"."previous_lead_id" is null and "leads"."listing_id" is not null;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "listings_external_uq" ON "listings" USING btree ("external_id");--> statement-breakpoint
|
||||
CREATE INDEX "listings_phone_idx" ON "listings" USING btree ("phone");--> statement-breakpoint
|
||||
CREATE INDEX "outbox_due_idx" ON "outbox" USING btree ("run_at") WHERE "outbox"."done_at" is null;--> statement-breakpoint
|
||||
CREATE INDEX "statuses_company_idx" ON "pipeline_statuses" USING btree ("company_id","pipeline");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "users_telegram_uq" ON "users" USING btree ("telegram_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "users_email_uq" ON "users" USING btree (lower("email"));--> statement-breakpoint
|
||||
CREATE INDEX "users_company_idx" ON "users" USING btree ("company_id");
|
||||
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE "events" ADD COLUMN "status_id" integer;--> statement-breakpoint
|
||||
UPDATE "events" e SET "status_id" = s."id"
|
||||
FROM "pipeline_statuses" s
|
||||
WHERE e."type" IN ('status', 'deal') AND s."company_id" = e."company_id" AND s."name" = e."new_value"
|
||||
AND s."pipeline" = CASE WHEN e."lead_id" IS NOT NULL THEN 'object' ELSE 'client' END;
|
||||
--> statement-breakpoint
|
||||
UPDATE "events" e SET "status_id" = s."id"
|
||||
FROM "pipeline_statuses" s
|
||||
WHERE e."type" = 'blacklisted' AND s."company_id" = e."company_id" AND s."pipeline" = 'object' AND s."code" = 'rejected';
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE "settings" (
|
||||
"key" text PRIMARY KEY NOT NULL,
|
||||
"value" jsonb NOT NULL,
|
||||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,8 @@
|
||||
ALTER TABLE "admin_messages" ADD COLUMN "unreachable" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "companies" ADD COLUMN "percent_from" date;--> statement-breakpoint
|
||||
ALTER TABLE "companies" ADD COLUMN "billing_notice" text;--> statement-breakpoint
|
||||
ALTER TABLE "sessions" ADD COLUMN "via_telegram" boolean DEFAULT false NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD COLUMN "onboarded_at" timestamp with time zone;--> statement-breakpoint
|
||||
-- Уже работающим пользователям мастер настройки не показывается.
|
||||
UPDATE "users" SET "onboarded_at" = "created_at" WHERE "company_id" IS NOT NULL;--> statement-breakpoint
|
||||
UPDATE "companies" SET "percent_from" = ("created_at" AT TIME ZONE 'Asia/Yerevan')::date WHERE "billing_model" = 'percent';
|
||||
@@ -0,0 +1,32 @@
|
||||
CREATE TABLE "support_messages" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"ticket_id" integer NOT NULL,
|
||||
"from_support" boolean DEFAULT false NOT NULL,
|
||||
"author_id" integer,
|
||||
"text" text,
|
||||
"file_id" text,
|
||||
"file_kind" text,
|
||||
"file_name" text,
|
||||
"at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "support_tickets" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"chat_id" bigint NOT NULL,
|
||||
"user_id" integer,
|
||||
"tg_name" text,
|
||||
"tg_username" text,
|
||||
"status" text DEFAULT 'open' NOT NULL,
|
||||
"unread" boolean DEFAULT true NOT NULL,
|
||||
"last_message_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
"closed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "outbox" ALTER COLUMN "user_id" DROP NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "support_messages" ADD CONSTRAINT "support_messages_ticket_id_support_tickets_id_fk" FOREIGN KEY ("ticket_id") REFERENCES "public"."support_tickets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "support_messages" ADD CONSTRAINT "support_messages_author_id_users_id_fk" FOREIGN KEY ("author_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "support_tickets" ADD CONSTRAINT "support_tickets_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "support_messages_ticket_idx" ON "support_messages" USING btree ("ticket_id");--> statement-breakpoint
|
||||
CREATE INDEX "support_tickets_status_idx" ON "support_tickets" USING btree ("status","last_message_at");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "support_tickets_open_uq" ON "support_tickets" USING btree ("chat_id") WHERE "support_tickets"."status" = 'open';
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE "client_photos" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"client_id" integer NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"content_type" text NOT NULL,
|
||||
"size" integer NOT NULL,
|
||||
"data" text NOT NULL,
|
||||
"uploaded_by_id" integer,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD COLUMN "household" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "features" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "listings" ADD COLUMN "features" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "client_photos" ADD CONSTRAINT "client_photos_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_photos" ADD CONSTRAINT "client_photos_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_photos" ADD CONSTRAINT "client_photos_uploaded_by_id_users_id_fk" FOREIGN KEY ("uploaded_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "client_photos_client_idx" ON "client_photos" USING btree ("client_id");
|
||||
@@ -0,0 +1,58 @@
|
||||
CREATE TABLE "client_pages" (
|
||||
"token" text PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"client_id" integer NOT NULL,
|
||||
"created_by_id" integer NOT NULL,
|
||||
"revoked_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "intake_links" (
|
||||
"token" text PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "intake_sessions" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"link_token" text NOT NULL,
|
||||
"chat_id" bigint NOT NULL,
|
||||
"tg_name" text,
|
||||
"tg_username" text,
|
||||
"lang" text DEFAULT 'ru' NOT NULL,
|
||||
"step" text NOT NULL,
|
||||
"answers" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
||||
"client_id" integer,
|
||||
"completed_at" timestamp with time zone,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "viewings" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"client_id" integer NOT NULL,
|
||||
"lead_id" integer NOT NULL,
|
||||
"day" date NOT NULL,
|
||||
"note" text,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "companies" ADD COLUMN "slug" text;--> statement-breakpoint
|
||||
ALTER TABLE "client_pages" ADD CONSTRAINT "client_pages_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_pages" ADD CONSTRAINT "client_pages_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "client_pages" ADD CONSTRAINT "client_pages_created_by_id_users_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "intake_links" ADD CONSTRAINT "intake_links_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "intake_links" ADD CONSTRAINT "intake_links_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "intake_sessions" ADD CONSTRAINT "intake_sessions_link_token_intake_links_token_fk" FOREIGN KEY ("link_token") REFERENCES "public"."intake_links"("token") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "intake_sessions" ADD CONSTRAINT "intake_sessions_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "viewings" ADD CONSTRAINT "viewings_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "viewings" ADD CONSTRAINT "viewings_client_id_clients_id_fk" FOREIGN KEY ("client_id") REFERENCES "public"."clients"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "viewings" ADD CONSTRAINT "viewings_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "client_pages_client_uq" ON "client_pages" USING btree ("client_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "intake_links_user_uq" ON "intake_links" USING btree ("user_id");--> statement-breakpoint
|
||||
CREATE INDEX "intake_sessions_chat_idx" ON "intake_sessions" USING btree ("chat_id");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "viewings_uq" ON "viewings" USING btree ("client_id","lead_id");--> statement-breakpoint
|
||||
ALTER TABLE "companies" ADD CONSTRAINT "companies_slug_unique" UNIQUE("slug");--> statement-breakpoint
|
||||
-- У уже созданных компаний адрес страниц — «c<номер>»; руководитель может поменять его в настройках.
|
||||
UPDATE "companies" SET "slug" = 'c' || "id" WHERE "slug" IS NULL;
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE "leads" ADD COLUMN "showcase_text" text;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "gallery_at" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "gallery_tries" integer DEFAULT 0 NOT NULL;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE "leads" ADD COLUMN "gallery_wanted_at" timestamp with time zone;
|
||||
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE "listing_phones" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"listing_id" integer NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"user_id" integer,
|
||||
"phone" text NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "listing_phones" ADD CONSTRAINT "listing_phones_listing_id_listings_id_fk" FOREIGN KEY ("listing_id") REFERENCES "public"."listings"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "listing_phones" ADD CONSTRAINT "listing_phones_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "listing_phones" ADD CONSTRAINT "listing_phones_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "listing_phones_uq" ON "listing_phones" USING btree ("listing_id","company_id");--> statement-breakpoint
|
||||
CREATE INDEX "listing_phones_phone_idx" ON "listing_phones" USING btree ("listing_id","phone");--> statement-breakpoint
|
||||
-- Номера, уже внесённые агентами, становятся вариантами в общей базе.
|
||||
INSERT INTO "listing_phones" ("listing_id", "company_id", "phone")
|
||||
SELECT DISTINCT ON (l."listing_id", l."company_id") l."listing_id", l."company_id", l."phone"
|
||||
FROM "leads" l WHERE l."listing_id" IS NOT NULL AND l."phone" IS NOT NULL
|
||||
ORDER BY l."listing_id", l."company_id", l."id" DESC
|
||||
ON CONFLICT DO NOTHING;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE "clients" ADD COLUMN "commission" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "commission" jsonb;
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE "users" ADD COLUMN "pay" jsonb;
|
||||
@@ -0,0 +1,19 @@
|
||||
ALTER TABLE "deals" ADD COLUMN "owner_commission" numeric(14, 2) DEFAULT 0 NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD COLUMN "client_commission" numeric(14, 2) DEFAULT 0 NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD COLUMN "owner_agent_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD COLUMN "client_agent_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD COLUMN "kind" text DEFAULT 'sale' NOT NULL;--> statement-breakpoint
|
||||
-- Прежние сделки остаются целиком за тем, кто их закрыл: сумма — на стороне объекта, если он есть, иначе на стороне клиента.
|
||||
UPDATE "deals" SET
|
||||
"owner_agent_id" = "agent_id",
|
||||
"client_agent_id" = "agent_id",
|
||||
"owner_commission" = CASE WHEN "lead_id" IS NOT NULL THEN "commission" ELSE 0 END,
|
||||
"client_commission" = CASE WHEN "lead_id" IS NOT NULL THEN 0 ELSE "commission" END;--> statement-breakpoint
|
||||
UPDATE "deals" d SET "kind" = 'rent'
|
||||
WHERE EXISTS (SELECT 1 FROM "leads" l WHERE l."id" = d."lead_id" AND l."deal_type" = 'rent')
|
||||
OR (NOT EXISTS (SELECT 1 FROM "leads" l WHERE l."id" = d."lead_id" AND l."deal_type" IS NOT NULL)
|
||||
AND EXISTS (SELECT 1 FROM "clients" c WHERE c."id" = d."client_id" AND c."kind" = 'tenant'));--> statement-breakpoint
|
||||
ALTER TABLE "deals" ALTER COLUMN "owner_agent_id" SET NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ALTER COLUMN "client_agent_id" SET NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_owner_agent_id_users_id_fk" FOREIGN KEY ("owner_agent_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "deals" ADD CONSTRAINT "deals_client_agent_id_users_id_fk" FOREIGN KEY ("client_agent_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;
|
||||
@@ -0,0 +1,35 @@
|
||||
CREATE TABLE "pay_adjustments" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"month" text NOT NULL,
|
||||
"amount" numeric(14, 2) NOT NULL,
|
||||
"currency" text NOT NULL,
|
||||
"note" text NOT NULL,
|
||||
"created_by" integer NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "payouts" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"user_id" integer NOT NULL,
|
||||
"month" text NOT NULL,
|
||||
"amount" numeric(14, 2) NOT NULL,
|
||||
"currency" text NOT NULL,
|
||||
"paid_at" date NOT NULL,
|
||||
"note" text,
|
||||
"snapshot" jsonb NOT NULL,
|
||||
"created_by" integer NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "pay_adjustments" ADD CONSTRAINT "pay_adjustments_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "payouts" ADD CONSTRAINT "payouts_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "payouts" ADD CONSTRAINT "payouts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "payouts" ADD CONSTRAINT "payouts_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "pay_adjustments_user_month_idx" ON "pay_adjustments" USING btree ("company_id","user_id","month");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "payouts_user_month_uq" ON "payouts" USING btree ("user_id","month");--> statement-breakpoint
|
||||
CREATE INDEX "payouts_company_idx" ON "payouts" USING btree ("company_id");
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE "bot_langs" (
|
||||
"telegram_id" bigint PRIMARY KEY NOT NULL,
|
||||
"lang" text NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE "leads" ADD COLUMN "bumped_at" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "listings" ADD COLUMN "bumped_at" timestamp with time zone;--> statement-breakpoint
|
||||
ALTER TABLE "parser_state" ADD COLUMN "top_ids" jsonb;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE "clients" ADD COLUMN "telegram" text;--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD COLUMN "rent_term" text;
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE "leads" ADD COLUMN "group_posted_commission" jsonb;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "group_posted_at" timestamp with time zone;
|
||||
@@ -0,0 +1,37 @@
|
||||
CREATE TABLE "departments" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"company_id" integer NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "lead_favorites" (
|
||||
"user_id" integer NOT NULL,
|
||||
"lead_id" integer NOT NULL,
|
||||
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "lead_favorites_user_id_lead_id_pk" PRIMARY KEY("user_id","lead_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "lead_views" (
|
||||
"user_id" integer NOT NULL,
|
||||
"lead_id" integer NOT NULL,
|
||||
"viewed_at" timestamp with time zone DEFAULT now() NOT NULL,
|
||||
CONSTRAINT "lead_views_user_id_lead_id_pk" PRIMARY KEY("user_id","lead_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DROP INDEX "leads_company_listing_uq";--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD COLUMN "department_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "filters" ADD COLUMN "department_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD COLUMN "department_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD COLUMN "department_id" integer;--> statement-breakpoint
|
||||
ALTER TABLE "departments" ADD CONSTRAINT "departments_company_id_companies_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_favorites" ADD CONSTRAINT "lead_favorites_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_favorites" ADD CONSTRAINT "lead_favorites_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_views" ADD CONSTRAINT "lead_views_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "lead_views" ADD CONSTRAINT "lead_views_lead_id_leads_id_fk" FOREIGN KEY ("lead_id") REFERENCES "public"."leads"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "departments_company_idx" ON "departments" USING btree ("company_id");--> statement-breakpoint
|
||||
ALTER TABLE "clients" ADD CONSTRAINT "clients_department_id_departments_id_fk" FOREIGN KEY ("department_id") REFERENCES "public"."departments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "filters" ADD CONSTRAINT "filters_department_id_departments_id_fk" FOREIGN KEY ("department_id") REFERENCES "public"."departments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "leads" ADD CONSTRAINT "leads_department_id_departments_id_fk" FOREIGN KEY ("department_id") REFERENCES "public"."departments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "users" ADD CONSTRAINT "users_department_id_departments_id_fk" FOREIGN KEY ("department_id") REFERENCES "public"."departments"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "leads_company_dept_listing_uq" ON "leads" USING btree ("company_id",coalesce("department_id", 0),"listing_id") WHERE "leads"."previous_lead_id" is null and "leads"."listing_id" is not null;
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,139 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1791474709969,
|
||||
"tag": "0000_busy_kat_farrell",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1791486109720,
|
||||
"tag": "0001_left_lady_deathstrike",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "7",
|
||||
"when": 1791487573067,
|
||||
"tag": "0002_black_shocker",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "7",
|
||||
"when": 1791538527629,
|
||||
"tag": "0003_sharp_giant_girl",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "7",
|
||||
"when": 1791542601013,
|
||||
"tag": "0004_eager_mockingbird",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 5,
|
||||
"version": "7",
|
||||
"when": 1791548601291,
|
||||
"tag": "0005_left_slapstick",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 6,
|
||||
"version": "7",
|
||||
"when": 1791550647233,
|
||||
"tag": "0006_thick_umar",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 7,
|
||||
"version": "7",
|
||||
"when": 1791552698846,
|
||||
"tag": "0007_chilly_maddog",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 8,
|
||||
"version": "7",
|
||||
"when": 1791553975016,
|
||||
"tag": "0008_concerned_cardiac",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 9,
|
||||
"version": "7",
|
||||
"when": 1791555219811,
|
||||
"tag": "0009_bizarre_randall_flagg",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 10,
|
||||
"version": "7",
|
||||
"when": 1791555417590,
|
||||
"tag": "0010_wakeful_exodus",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 11,
|
||||
"version": "7",
|
||||
"when": 1791558446545,
|
||||
"tag": "0011_soft_edwin_jarvis",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 12,
|
||||
"version": "7",
|
||||
"when": 1791913393916,
|
||||
"tag": "0012_organic_thing",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 13,
|
||||
"version": "7",
|
||||
"when": 1791915450918,
|
||||
"tag": "0013_shallow_kabuki",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 14,
|
||||
"version": "7",
|
||||
"when": 1791918705929,
|
||||
"tag": "0014_modern_gabe_jones",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 15,
|
||||
"version": "7",
|
||||
"when": 1792148447759,
|
||||
"tag": "0015_supreme_clint_barton",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 16,
|
||||
"version": "7",
|
||||
"when": 1792444245607,
|
||||
"tag": "0016_massive_maria_hill",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 17,
|
||||
"version": "7",
|
||||
"when": 1792445277037,
|
||||
"tag": "0017_open_gabe_jones",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 18,
|
||||
"version": "7",
|
||||
"when": 1792954204010,
|
||||
"tag": "0018_elite_magdalene",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user