From f99209aaa22844c8691a2bdd2d97930c71d4b314 Mon Sep 17 00:00:00 2001 From: ThienLK Date: Thu, 8 Aug 2024 14:27:20 +0700 Subject: [PATCH] add chapter collection --- .../tables/public_chapter_collection.yaml | 10 ++++++++++ .../databases/punkga-pg/tables/tables.yaml | 1 + hasura/metadata/query_collections.yaml | 20 +++++++++++++++++++ hasura/metadata/rest_endpoints.yaml | 18 +++++++++++++++++ .../down.sql | 1 + .../up.sql | 17 ++++++++++++++++ 6 files changed, 67 insertions(+) create mode 100644 hasura/metadata/databases/punkga-pg/tables/public_chapter_collection.yaml create mode 100644 hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/down.sql create mode 100644 hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/up.sql diff --git a/hasura/metadata/databases/punkga-pg/tables/public_chapter_collection.yaml b/hasura/metadata/databases/punkga-pg/tables/public_chapter_collection.yaml new file mode 100644 index 0000000..ee96ee0 --- /dev/null +++ b/hasura/metadata/databases/punkga-pg/tables/public_chapter_collection.yaml @@ -0,0 +1,10 @@ +table: + name: chapter_collection + schema: public +object_relationships: + - name: chapter_collection + using: + foreign_key_constraint_on: launchpad_id + - name: collection_chapter + using: + foreign_key_constraint_on: chapter_id diff --git a/hasura/metadata/databases/punkga-pg/tables/tables.yaml b/hasura/metadata/databases/punkga-pg/tables/tables.yaml index 4f4ab8a..d522306 100644 --- a/hasura/metadata/databases/punkga-pg/tables/tables.yaml +++ b/hasura/metadata/databases/punkga-pg/tables/tables.yaml @@ -5,6 +5,7 @@ - "!include public_banners.yaml" - "!include public_campaign.yaml" - "!include public_chains.yaml" +- "!include public_chapter_collection.yaml" - "!include public_chapter_languages.yaml" - "!include public_chapter_total_likes.yaml" - "!include public_chapters.yaml" diff --git a/hasura/metadata/query_collections.yaml b/hasura/metadata/query_collections.yaml index 9c275a3..5ebeeed 100644 --- a/hasura/metadata/query_collections.yaml +++ b/hasura/metadata/query_collections.yaml @@ -1385,3 +1385,23 @@ id } } + - name: Admin - Delete Chapter Collection + query: | + mutation delete_chapter_collection_by_pk ($id: Int!) { + delete_chapter_collection_by_pk(id: $id) { + id + } + } + - name: Admin - Insert Chapter Collection + query: | + mutation MyMutation ($objects: [chapter_collection_insert_input!] = {}) { + insert_chapter_collection(objects: $objects, on_conflict: {constraint:chapter_collection_chapter_id_launchpad_id_key,update_columns:chapter_id}) { + affected_rows + returning { + chapter_id + created_at + id + launchpad_id + } + } + } diff --git a/hasura/metadata/rest_endpoints.yaml b/hasura/metadata/rest_endpoints.yaml index 57b0392..981da4a 100644 --- a/hasura/metadata/rest_endpoints.yaml +++ b/hasura/metadata/rest_endpoints.yaml @@ -34,6 +34,24 @@ - GET name: Admin - Query campaign detail url: admin/campaign/:id +- comment: Delete Chapter Collection + definition: + query: + collection_name: allowed-queries + query_name: Admin - Delete Chapter Collection + methods: + - DELETE + name: Admin - Delete Chapter Collection + url: admin/chapter-collection +- comment: "Insert Chapter Collection\nchapter_collection_insert_input:{\nchapter_id: Int!, \nlaunchpad_id: Int!\n}" + definition: + query: + collection_name: allowed-queries + query_name: Admin - Insert Chapter Collection + methods: + - POST + name: Admin - Insert Chapter Collection + url: admin/chapter-collection - comment: "" definition: query: diff --git a/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/down.sql b/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/down.sql new file mode 100644 index 0000000..31f912b --- /dev/null +++ b/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/down.sql @@ -0,0 +1 @@ +DROP TABLE "public"."chapter_collection"; diff --git a/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/up.sql b/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/up.sql new file mode 100644 index 0000000..f3bb933 --- /dev/null +++ b/hasura/migrations/punkga-pg/1723100828427_create_table_public_chapter_collection/up.sql @@ -0,0 +1,17 @@ +CREATE TABLE "public"."chapter_collection" ("id" serial NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), "chapter_id" integer NOT NULL, "launchpad_id" integer NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("chapter_id") REFERENCES "public"."chapters"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("launchpad_id") REFERENCES "public"."launchpad"("id") ON UPDATE cascade ON DELETE cascade, UNIQUE ("chapter_id", "launchpad_id")); +CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"() +RETURNS TRIGGER AS $$ +DECLARE + _new record; +BEGIN + _new := NEW; + _new."updated_at" = NOW(); + RETURN _new; +END; +$$ LANGUAGE plpgsql; +CREATE TRIGGER "set_public_chapter_collection_updated_at" +BEFORE UPDATE ON "public"."chapter_collection" +FOR EACH ROW +EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"(); +COMMENT ON TRIGGER "set_public_chapter_collection_updated_at" ON "public"."chapter_collection" +IS 'trigger to set value of column "updated_at" to current timestamp on row update';