From c13908324dc4efe45c0a6c70619787b0520695b2 Mon Sep 17 00:00:00 2001 From: HungLV Date: Wed, 14 Aug 2024 09:20:22 +0700 Subject: [PATCH] fix: migration --- .../migration.sql | 12 ------------ .../migration.sql | 17 ----------------- .../migration.sql | 3 +++ prisma/schema.prisma | 4 ++-- 4 files changed, 5 insertions(+), 31 deletions(-) delete mode 100644 prisma/migrations/20240808080505_alter_products_and_collections_timestamp_fields/migration.sql delete mode 100644 prisma/migrations/20240809081547_updated_at_trigger/migration.sql create mode 100644 prisma/migrations/20240814021956_alter_table_products_and_collections_2/migration.sql diff --git a/prisma/migrations/20240808080505_alter_products_and_collections_timestamp_fields/migration.sql b/prisma/migrations/20240808080505_alter_products_and_collections_timestamp_fields/migration.sql deleted file mode 100644 index a8b3958..0000000 --- a/prisma/migrations/20240808080505_alter_products_and_collections_timestamp_fields/migration.sql +++ /dev/null @@ -1,12 +0,0 @@ -/* - Warnings: - - - Added the required column `updated_at` to the `collections` table without a default value. This is not possible if the table is not empty. - -*/ --- AlterTable -ALTER TABLE "collections" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, -ADD COLUMN "updated_at" TIMESTAMP(3) NOT NULL; - --- AlterTable -ALTER TABLE "products" ALTER COLUMN "updated_at" DROP DEFAULT; diff --git a/prisma/migrations/20240809081547_updated_at_trigger/migration.sql b/prisma/migrations/20240809081547_updated_at_trigger/migration.sql deleted file mode 100644 index fc31672..0000000 --- a/prisma/migrations/20240809081547_updated_at_trigger/migration.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE OR REPLACE FUNCTION update_timestamp() -RETURNS TRIGGER AS $$ -BEGIN - NEW.updated_at = NOW(); - RETURN NEW; -END; -$$ LANGUAGE plpgsql; - -CREATE TRIGGER products_updated_at_timestamp_trigger -BEFORE UPDATE ON products -FOR EACH ROW -EXECUTE FUNCTION update_timestamp(); - -CREATE TRIGGER collections_updated_at_timestamp_trigger -BEFORE UPDATE ON collections -FOR EACH ROW -EXECUTE FUNCTION update_timestamp(); diff --git a/prisma/migrations/20240814021956_alter_table_products_and_collections_2/migration.sql b/prisma/migrations/20240814021956_alter_table_products_and_collections_2/migration.sql new file mode 100644 index 0000000..ed2e4ae --- /dev/null +++ b/prisma/migrations/20240814021956_alter_table_products_and_collections_2/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "collections" ADD COLUMN "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 18c92c9..c89a3f9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -43,7 +43,7 @@ model Product { owner_id Int featured_at DateTime? created_at DateTime @default(now()) - updated_at DateTime @updatedAt + updated_at DateTime @default(now()) @updatedAt stat_total_collection Int? stat_total_items Int? @@ -95,7 +95,7 @@ model Collection { nfts Nft[] product Product @relation(fields: [product_id], references: [id]) created_at DateTime @default(now()) - updated_at DateTime @updatedAt + updated_at DateTime @default(now()) @updatedAt @@unique([chain_id, contract_address]) @@index(product_id)