Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Sep 19, 2024
2 parents 46e359e + 63a68cd commit b96033c
Show file tree
Hide file tree
Showing 65 changed files with 15,341 additions and 1,720 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ tsconfig.tsbuildinfo
*.pem*
credentials/*

src/test/**/*.json
src/test/**/*.json
*.exe
43 changes: 43 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/public_albums.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,46 @@ array_relationships:
table:
name: artworks
schema: public
select_permissions:
- role: anonymous
permission:
columns:
- created_at
- creator_id
- description
- disable
- id
- name
- show
- thumbnail_url
- updated_at
filter: {}
allow_aggregations: true
- role: creator
permission:
columns:
- created_at
- creator_id
- description
- disable
- id
- name
- show
- thumbnail_url
- updated_at
filter: {}
allow_aggregations: true
- role: user
permission:
columns:
- created_at
- creator_id
- description
- disable
- id
- name
- show
- thumbnail_url
- updated_at
filter: {}
allow_aggregations: true
20 changes: 19 additions & 1 deletion hasura/metadata/databases/punkga-pg/tables/public_artworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,41 @@ select_permissions:
- role: anonymous
permission:
columns:
- album_id
- contest_id
- contest_round
- created_at
- creator_id
- id
- name
- source_url
- updated_at
- url
filter: {}
allow_aggregations: true
- role: creator
permission:
columns:
- album_id
- contest_id
- contest_round
- creator_id
- id
- name
- source_url
- url
- created_at
- updated_at
filter: {}
allow_aggregations: true
- role: user
permission:
columns:
- album_id
- contest_id
- contest_round
- creator_id
- id
- name
- source_url
- url
- created_at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
table:
name: donate_history
schema: public
object_relationships:
- name: creator
using:
foreign_key_constraint_on: creator_id
- name: telegram_user
using:
foreign_key_constraint_on: telegram_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
table:
name: telegram_quest_history
schema: public
object_relationships:
- name: telegram_quest
using:
foreign_key_constraint_on: quest_id
- name: telegram_user
using:
foreign_key_constraint_on: telegram_user_id
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table:
name: telegram_quests
schema: public
array_relationships:
- name: telegram_quest_histories
using:
foreign_key_constraint_on:
column: quest_id
table:
name: telegram_quest_history
schema: public
3 changes: 3 additions & 0 deletions hasura/metadata/databases/punkga-pg/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- "!include public_chapters.yaml"
- "!include public_contest.yaml"
- "!include public_creators.yaml"
- "!include public_donate_history.yaml"
- "!include public_email_subscribe.yaml"
- "!include public_i18n.yaml"
- "!include public_languages.yaml"
Expand All @@ -34,6 +35,8 @@
- "!include public_system_key.yaml"
- "!include public_tag_languages.yaml"
- "!include public_tags.yaml"
- "!include public_telegram_quest_history.yaml"
- "!include public_telegram_quests.yaml"
- "!include public_telegram_users.yaml"
- "!include public_user_campaign.yaml"
- "!include public_user_campaign_reward.yaml"
Expand Down
44 changes: 44 additions & 0 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1472,3 +1472,47 @@
}
}
}
- name: Public - Query albums by creator id
query: |
query albums ($creator_id: Int!) {
albums(where: {creator_id:{_eq:$creator_id},show:{_eq:true}}, limit: 10, offset: 0) {
id
show
thumbnail_url
name
disable
}
albums_aggregate(where: {creator_id:{_eq:$creator_id},show:{_eq:true}}) {
aggregate {
count
}
}
default: albums_by_pk(id: 1) {
id
show
thumbnail_url
name
disable
}
}
- name: Public - Query album detail
query: |
query albums ($id: Int!, $limit: Int = 10, $offset: Int = 0) {
albums(where: {id:{_eq:$id},show:{_eq:true},disable:{_eq:false}}) {
id
name
thumbnail_url
show
disable
artworks(limit: $limit, offset: $offset) {
id
name
url
}
artworks_aggregate {
aggregate {
count
}
}
}
}
18 changes: 18 additions & 0 deletions hasura/metadata/rest_endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@
- GET
name: Public - Get leaderboard
url: pubic/leaderboard
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Public - Query album detail
methods:
- GET
name: Public - Query album detail
url: public/albums/:id
- comment: ""
definition:
query:
Expand Down Expand Up @@ -286,6 +295,15 @@
- GET
name: Public - Get Chapter Comments
url: public/chapters/:chapter_id/comments
- comment: ""
definition:
query:
collection_name: allowed-queries
query_name: Public - Query albums by creator id
methods:
- GET
name: Public - Query albums by creator id
url: public/creators/:creator_id/albums
- comment: ""
definition:
query:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."donate_history";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."donate_history" ("id" serial NOT NULL, "telegram_id" text NOT NULL, "creator_id" integer NOT NULL, "txn" text NOT NULL, "value" text NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , FOREIGN KEY ("telegram_id") REFERENCES "public"."telegram_users"("telegram_id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("creator_id") REFERENCES "public"."creators"("id") ON UPDATE cascade ON DELETE cascade);
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_donate_history_updated_at"
BEFORE UPDATE ON "public"."donate_history"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_donate_history_updated_at" ON "public"."donate_history"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."donate_history" alter column "value" drop not null;
alter table "public"."donate_history" add column "value" text;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."donate_history" drop column "value" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."donate_history" add column "value" Integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."donate_history" add column "value" Integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- CREATE OR REPLACE FUNCTION update_show_album_fnc() RETURNS trigger AS $$
-- DECLARE
-- cnt integer;
-- BEGIN
-- SELECT count(*) INTO cnt FROM artworks a WHERE a.album_id = OLD.album_id;
-- IF cnt = 0 THEN
-- UPDATE albums SET show = false WHERE id = OLD.album_id;
-- END IF;
-- RETURN OLD;
-- END;
-- $$ LANGUAGE plpgsql;
--
-- CREATE OR REPLACE TRIGGER update_show_album
-- AFTER DELETE ON artworks
-- FOR EACH ROW
-- EXECUTE FUNCTION update_show_album_fnc();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE OR REPLACE FUNCTION update_show_album_fnc() RETURNS trigger AS $$
DECLARE
cnt integer;
BEGIN
SELECT count(*) INTO cnt FROM artworks a WHERE a.album_id = OLD.album_id;
IF cnt = 0 THEN
UPDATE albums SET show = false WHERE id = OLD.album_id;
END IF;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER update_show_album
AFTER DELETE ON artworks
FOR EACH ROW
EXECUTE FUNCTION update_show_album_fnc();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."telegram_users" add column "chip" bigint
-- null default '0';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."telegram_users" add column "chip" bigint
null default '0';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."telegram_quests";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."telegram_quests" ("id" bigserial NOT NULL, "quest_name" text NOT NULL, "quest_url" text NOT NULL, "reward" bigint NOT NULL, "claim_after" integer NOT NULL DEFAULT 0, "social_source" text NOT NULL, "type" text NOT NULL, "active_from" date NOT NULL, "active_to" date NOT NULL, "activated" boolean NOT NULL DEFAULT true, "deleted" boolean NOT NULL DEFAULT false, PRIMARY KEY ("id") , UNIQUE ("id"));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quests" alter column "active_from" set not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quests" alter column "active_from" drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quests" alter column "active_to" set not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quests" alter column "active_to" drop not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."telegram_quest_history";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."telegram_quest_history" ("id" bigserial NOT NULL, "quest_id" bigint NOT NULL, "telegram_user_id" integer NOT NULL, "is_claim" boolean NOT NULL, "created_date_utc" date NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("quest_id") REFERENCES "public"."telegram_quests"("id") ON UPDATE restrict ON DELETE no action, UNIQUE ("id"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."telegram_quest_history"
add constraint "telegram_quest_history_quest_id_fkey"
foreign key ("quest_id")
references "public"."telegram_quests"
("id") on update restrict on delete no action;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quest_history" drop constraint "telegram_quest_history_quest_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quest_history" drop constraint "telegram_quest_history_quest_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."telegram_quest_history"
add constraint "telegram_quest_history_quest_id_fkey"
foreign key ("quest_id")
references "public"."telegram_quests"
("id") on update restrict on delete no action;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."telegram_quest_history" drop constraint "telegram_quest_history_telegram_user_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."telegram_quest_history"
add constraint "telegram_quest_history_telegram_user_id_fkey"
foreign key ("telegram_user_id")
references "public"."telegram_users"
("id") on update restrict on delete no action;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."telegram_quest_history" rename column "created_date" to "created_date_utc";
ALTER TABLE "public"."telegram_quest_history" ALTER COLUMN "created_date_utc" drop default;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."telegram_quest_history" alter column "created_date_utc" set default now();
alter table "public"."telegram_quest_history" rename column "created_date_utc" to "created_date";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "public"."telegram_quest_history" ALTER COLUMN "created_date" TYPE date;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "public"."telegram_quest_history" ALTER COLUMN "created_date" TYPE timestamp;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."donate_history" add column "send_to_creator" boolean
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."donate_history" add column "send_to_creator" boolean
null;
Loading

0 comments on commit b96033c

Please sign in to comment.