database fix (broke migrations!)

This commit is contained in:
mihalin 2021-09-11 01:11:37 +03:00
parent f448d2c0c8
commit 0306b6737a
3 changed files with 8 additions and 10 deletions

View File

@ -1,5 +0,0 @@
-- upgrade --
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
ALTER TABLE "bot" ADD "code" UUID NOT NULL DEFAULT uuid_generate_v4();
-- downgrade --
ALTER TABLE "bot" DROP COLUMN "code";

View File

@ -14,10 +14,12 @@ CREATE TABLE IF NOT EXISTS "bot" (
"id" SERIAL NOT NULL PRIMARY KEY,
"token" VARCHAR(50) NOT NULL UNIQUE,
"name" VARCHAR(33) NOT NULL,
"code" UUID NOT NULL,
"start_text" TEXT NOT NULL,
"group_chat_id" INT REFERENCES "group_chat" ("id") ON DELETE SET NULL,
"group_chat_id" INT REFERENCES "group_chat" ("id") ON DELETE CASCADE,
"owner_id" INT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS "idx_bot_code_a43015" ON "bot" ("code");
CREATE TABLE IF NOT EXISTS "aerich" (
"id" SERIAL NOT NULL PRIMARY KEY,
"version" VARCHAR(255) NOT NULL,
@ -25,6 +27,6 @@ CREATE TABLE IF NOT EXISTS "aerich" (
"content" JSONB NOT NULL
);
CREATE TABLE IF NOT EXISTS "bot_group_chat" (
"bot_id" INT NOT NULL REFERENCES "bot" ("id") ON DELETE SET NULL,
"groupchat_id" INT NOT NULL REFERENCES "group_chat" ("id") ON DELETE SET NULL
"bot_id" INT NOT NULL REFERENCES "bot" ("id") ON DELETE CASCADE,
"groupchat_id" INT NOT NULL REFERENCES "group_chat" ("id") ON DELETE CASCADE
);

View File

@ -15,9 +15,10 @@ class Bot(Model):
Напишите ваш вопрос и мы ответим вам в ближайшее время.
"""))
group_chats = fields.ManyToManyField("models.GroupChat", related_name="bots", on_delete=fields.relational.SET_NULL)
group_chats = fields.ManyToManyField("models.GroupChat", related_name="bots", on_delete=fields.relational.CASCADE,
null=True)
group_chat = fields.ForeignKeyField("models.GroupChat", related_name="active_bots",
on_delete=fields.relational.SET_NULL,
on_delete=fields.relational.CASCADE,
null=True)
async def super_chat_id(self):