mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-02 03:00:32 -04:00
Update models (#33)
* Remove unused models * add new props into Player model * Added props to Guild * Setting guild type as a foreign-key reference * Use foreign table for skills * Seed data * prettier
This commit is contained in:
@@ -18,7 +18,7 @@ Create your local .env file
|
||||
cp .env.sample .env
|
||||
```
|
||||
|
||||
Initial TS Compilation For Monorepo Packages
|
||||
Initial TS Compilation For Monorepo Packages
|
||||
|
||||
```shell script
|
||||
yarn typecheck
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
columns:
|
||||
- player_id
|
||||
- identifier
|
||||
- linkToProof
|
||||
- type
|
||||
filter: {}
|
||||
- role: public
|
||||
@@ -19,55 +18,56 @@
|
||||
columns:
|
||||
- player_id
|
||||
- identifier
|
||||
- linkToProof
|
||||
- type
|
||||
filter: {}
|
||||
- table:
|
||||
schema: public
|
||||
name: Guild
|
||||
array_relationships:
|
||||
- name: Guild_Members
|
||||
object_relationships:
|
||||
- name: GuildType
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: guild_id
|
||||
table:
|
||||
schema: public
|
||||
name: Guild_Member
|
||||
foreign_key_constraint_on: type
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- type
|
||||
- identifier
|
||||
- name
|
||||
- logo
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- type
|
||||
- identifier
|
||||
- name
|
||||
- logo
|
||||
filter: {}
|
||||
- table:
|
||||
schema: public
|
||||
name: Guild_Member
|
||||
object_relationships:
|
||||
- name: Guild
|
||||
name: GuildType
|
||||
is_enum: true
|
||||
array_relationships:
|
||||
- name: Guilds
|
||||
using:
|
||||
foreign_key_constraint_on: guild_id
|
||||
- name: Player
|
||||
using:
|
||||
foreign_key_constraint_on: player_id
|
||||
foreign_key_constraint_on:
|
||||
column: type
|
||||
table:
|
||||
schema: public
|
||||
name: Guild
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- guild_id
|
||||
- player_id
|
||||
- name
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- guild_id
|
||||
- player_id
|
||||
- name
|
||||
filter: {}
|
||||
- table:
|
||||
schema: public
|
||||
@@ -80,134 +80,114 @@
|
||||
table:
|
||||
schema: public
|
||||
name: Account
|
||||
- name: Guild_Members
|
||||
- name: Player_Skills
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: player_id
|
||||
table:
|
||||
schema: public
|
||||
name: Guild_Member
|
||||
- name: Quest_Completeds
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: player_id
|
||||
table:
|
||||
schema: public
|
||||
name: Quest_Completed
|
||||
- name: XPIntervals
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: player_id
|
||||
table:
|
||||
schema: public
|
||||
name: XPInterval
|
||||
name: Player_Skill
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- links
|
||||
- rank
|
||||
- sentences
|
||||
- totalXp
|
||||
- username
|
||||
- enneagram
|
||||
- role
|
||||
- timezone
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- links
|
||||
- rank
|
||||
- sentences
|
||||
- totalXp
|
||||
- username
|
||||
- enneagram
|
||||
- role
|
||||
- timezone
|
||||
filter: {}
|
||||
update_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- sentences
|
||||
- username
|
||||
- enneagram
|
||||
- role
|
||||
- timezone
|
||||
filter:
|
||||
id:
|
||||
_eq: X-Hasura-User-Id
|
||||
check: null
|
||||
- table:
|
||||
schema: public
|
||||
name: Quest
|
||||
name: Player_Skill
|
||||
object_relationships:
|
||||
- name: Player
|
||||
using:
|
||||
foreign_key_constraint_on: player_id
|
||||
- name: Skill
|
||||
using:
|
||||
foreign_key_constraint_on: skill_id
|
||||
insert_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
check:
|
||||
player_id:
|
||||
_eq: X-Hasura-User-Id
|
||||
set:
|
||||
player_id: x-hasura-User-Id
|
||||
columns:
|
||||
- skill_id
|
||||
backend_only: false
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- player_id
|
||||
- skill_id
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- player_id
|
||||
- skill_id
|
||||
filter: {}
|
||||
delete_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
filter:
|
||||
player_id:
|
||||
_eq: X-Hasura-User-Id
|
||||
- table:
|
||||
schema: public
|
||||
name: Skill
|
||||
array_relationships:
|
||||
- name: Quest_Completeds
|
||||
- name: Player_Skills
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
column: quest_id
|
||||
column: skill_id
|
||||
table:
|
||||
schema: public
|
||||
name: Quest_Completed
|
||||
name: Player_Skill
|
||||
insert_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
check: {}
|
||||
columns:
|
||||
- name
|
||||
backend_only: false
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- name
|
||||
- description
|
||||
- url
|
||||
- xp
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- name
|
||||
- description
|
||||
- url
|
||||
- xp
|
||||
filter: {}
|
||||
- table:
|
||||
schema: public
|
||||
name: Quest_Completed
|
||||
object_relationships:
|
||||
- name: Player
|
||||
using:
|
||||
foreign_key_constraint_on: player_id
|
||||
- name: Quest
|
||||
using:
|
||||
foreign_key_constraint_on: quest_id
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- quest_id
|
||||
- player_id
|
||||
- time
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- quest_id
|
||||
- player_id
|
||||
- time
|
||||
filter: {}
|
||||
- table:
|
||||
schema: public
|
||||
name: XPInterval
|
||||
object_relationships:
|
||||
- name: Player
|
||||
using:
|
||||
foreign_key_constraint_on: player_id
|
||||
select_permissions:
|
||||
- role: player
|
||||
permission:
|
||||
columns:
|
||||
- player_id
|
||||
- startTime
|
||||
- endTime
|
||||
- xp
|
||||
filter: {}
|
||||
- role: public
|
||||
permission:
|
||||
columns:
|
||||
- player_id
|
||||
- startTime
|
||||
- endTime
|
||||
- xp
|
||||
- id
|
||||
filter: {}
|
||||
|
||||
@@ -8,80 +8,56 @@ CREATE TYPE account_type AS ENUM (
|
||||
'DISCOURSE'
|
||||
);
|
||||
|
||||
CREATE TYPE player_rank AS ENUM (
|
||||
'PLAYER',
|
||||
'BRONZE',
|
||||
'SILVER',
|
||||
'GOLDEN',
|
||||
'PLATINIUM',
|
||||
'DIAMOND'
|
||||
CREATE TYPE enneagram_type AS ENUM (
|
||||
'REFORMER',
|
||||
'HELPER',
|
||||
'ACHIEVER',
|
||||
'INDIVIDUALIST',
|
||||
'INVESTIGATOR',
|
||||
'LOYALIST',
|
||||
'ENTHUSIAST',
|
||||
'CHALLENGER',
|
||||
'PEACEMAKER'
|
||||
);
|
||||
|
||||
-- Tables
|
||||
|
||||
CREATE TABLE "Player" (
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL,
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL PRIMARY KEY,
|
||||
"username" text NOT NULL,
|
||||
"totalXp" numeric DEFAULT 0,
|
||||
"rank" player_rank NOT NULL DEFAULT 'PLAYER',
|
||||
"links" json,
|
||||
"sentences" json
|
||||
"role" text,
|
||||
"timezone" int,
|
||||
"enneagram" enneagram_type
|
||||
);
|
||||
|
||||
CREATE TABLE "Account" (
|
||||
"player_id" uuid NOT NULL,
|
||||
"identifier" text NOT NULL,
|
||||
"linkToProof" text,
|
||||
"type" account_type NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE "Quest" (
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"description" text,
|
||||
"url" text NOT NULL,
|
||||
"xp" numeric NOT NULL DEFAULT 0
|
||||
);
|
||||
|
||||
CREATE TABLE "Quest_Completed" (
|
||||
"quest_id" uuid NOT NULL,
|
||||
"player_id" uuid NOT NULL,
|
||||
"time" timestamp
|
||||
);
|
||||
|
||||
CREATE TABLE "XPInterval" (
|
||||
"player_id" uuid NOT NULL,
|
||||
"startTime" date,
|
||||
"endTime" date,
|
||||
"xp" numeric NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE "Guild" (
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL,
|
||||
"name" text
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL PRIMARY KEY,
|
||||
"type" text NOT NULL,
|
||||
"identifier" text NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"logo" text
|
||||
);
|
||||
|
||||
CREATE TABLE "Guild_Member" (
|
||||
"guild_id" uuid NOT NULL,
|
||||
"player_id" uuid NOT NULL
|
||||
CREATE TABLE "GuildType" (
|
||||
"name" text NOT NULL PRIMARY KEY
|
||||
);
|
||||
|
||||
-- Primary keys
|
||||
CREATE TABLE "Skill" (
|
||||
"id" uuid DEFAULT public.gen_random_uuid() NOT NULL PRIMARY KEY,
|
||||
"name" text NOT NULL
|
||||
);
|
||||
|
||||
ALTER TABLE ONLY public."Player"
|
||||
ADD CONSTRAINT "Player_pkey" PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE ONLY public."Quest"
|
||||
ADD CONSTRAINT "Quest_pkey" PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE ONLY public."Guild"
|
||||
ADD CONSTRAINT "Guild_pkey" PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE ONLY public."Quest_Completed"
|
||||
ADD CONSTRAINT "Quest_Completed_pkey" PRIMARY KEY (quest_id, player_id);
|
||||
|
||||
ALTER TABLE ONLY public."Guild_Member"
|
||||
ADD CONSTRAINT "Guild_Member_pkey" PRIMARY KEY (guild_id, player_id);
|
||||
CREATE TABLE "Player_Skill" (
|
||||
"player_id" uuid NOT NULL,
|
||||
"skill_id" uuid NOT NULL
|
||||
);
|
||||
|
||||
-- Uniques
|
||||
|
||||
@@ -93,14 +69,22 @@ ALTER TABLE ONLY public."Account"
|
||||
ALTER TABLE ONLY public."Account"
|
||||
ADD CONSTRAINT "Account_identifier_type_player_key" UNIQUE (type, player_id);
|
||||
|
||||
ALTER TABLE ONLY public."Player_Skill"
|
||||
ADD CONSTRAINT "Player_Skill_unique_key" PRIMARY KEY (player_id, skill_id);
|
||||
|
||||
-- Foreign keys
|
||||
|
||||
ALTER TABLE "Account" ADD CONSTRAINT "Account_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "Player" ("id");
|
||||
|
||||
ALTER TABLE "Quest_Completed" ADD CONSTRAINT "Quest_Completed_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "Player" ("id");
|
||||
ALTER TABLE "Quest_Completed" ADD CONSTRAINT "Quest_Completed_quest_id_fkey" FOREIGN KEY ("quest_id") REFERENCES "Quest" ("id");
|
||||
ALTER TABLE "Player_Skill" ADD CONSTRAINT "Player_Skill_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "Player" ("id");
|
||||
ALTER TABLE "Player_Skill" ADD CONSTRAINT "Player_Skill_skill_id_fkey" FOREIGN KEY ("skill_id") REFERENCES "Skill" ("id");
|
||||
|
||||
ALTER TABLE "Guild_Member" ADD CONSTRAINT "Guild_Member_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "Player" ("id");
|
||||
ALTER TABLE "Guild_Member" ADD CONSTRAINT "Guild_Member_guild_id_fkey" FOREIGN KEY ("guild_id") REFERENCES "Guild" ("id");
|
||||
-- Foreign enums
|
||||
|
||||
ALTER TABLE "XPInterval" ADD CONSTRAINT "XPInterval_player_id_fkey" FOREIGN KEY ("player_id") REFERENCES "Player" ("id");
|
||||
ALTER TABLE "Guild" ADD CONSTRAINT
|
||||
"Guild_type_fkey" FOREIGN KEY ("type") REFERENCES "GuildType" ("name");
|
||||
|
||||
INSERT INTO "GuildType" ("name") VALUES
|
||||
('ARAGON'),
|
||||
('MOLOCH'),
|
||||
('EVEREST');
|
||||
|
||||
9
hasura/migrations/1595681063913_insert_seed_data/up.sql
Normal file
9
hasura/migrations/1595681063913_insert_seed_data/up.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
INSERT INTO "Player" (id, username) VALUES ('58f2911a-abcd-4210-a78b-c37dddca1157', 'pacobacpac');
|
||||
INSERT INTO "Account" (player_id, identifier, type) VALUES ('58f2911a-abcd-4210-a78b-c37dddca1157', '0x4194cE73AC3FBBeCE8fFa878c2B5A8C90333E724', 'ETHEREUM');
|
||||
INSERT INTO "Account" (player_id, identifier, type) VALUES ('58f2911a-abcd-4210-a78b-c37dddca1157', 'pakokrew', 'GITHUB');
|
||||
INSERT INTO "Account" (player_id, identifier, type) VALUES ('58f2911a-abcd-4210-a78b-c37dddca1157', 'pacobacpac', 'TWITTER');
|
||||
|
||||
INSERT INTO "Skill" (id, name) VALUES ('e3e96e33-abcd-4f8e-a3f3-b360a567055c', 'Javascript');
|
||||
INSERT INTO "Player_Skill" (player_id, skill_id) VALUES ('58f2911a-abcd-4210-a78b-c37dddca1157', 'e3e96e33-abcd-4f8e-a3f3-b360a567055c');
|
||||
|
||||
INSERT INTO "Guild" (id, type, identifier, name, logo) VALUES ('cd01cac9-abcd-42c3-908f-b8b0368eeef3', 'ARAGON', '0xd21cf378e2e40bda4597594738bb35e9ccc97da7', 'MetaFam', 'https://metagame.wtf/static/f3f97018016dd123ab7a9d6f8aaecc04/9911c/logo.png');
|
||||
@@ -73,7 +73,6 @@ async function updateVerifiedProfiles(
|
||||
player_id: playerId,
|
||||
type: 'GITHUB',
|
||||
identifier: verifiedProfiles.github.username,
|
||||
linkToProof: verifiedProfiles.github.proof,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -90,7 +89,6 @@ async function updateVerifiedProfiles(
|
||||
player_id: playerId,
|
||||
type: 'TWITTER',
|
||||
identifier: verifiedProfiles.twitter.username,
|
||||
linkToProof: verifiedProfiles.twitter.proof,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createClient } from 'urql'
|
||||
import { createClient } from 'urql';
|
||||
|
||||
export const client = createClient({
|
||||
url: 'https://graphql-pokemon.now.sh/',
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Pokemon } from '../types/pokemon';
|
||||
import { client } from './client'
|
||||
import { client } from './client';
|
||||
|
||||
const pokemonQuery = `
|
||||
query firstTwentyPokemons($name: String!) {
|
||||
@@ -8,13 +8,15 @@ const pokemonQuery = `
|
||||
image
|
||||
}
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export const getPokemon = async (name: string | undefined): Promise<Pokemon | null> => {
|
||||
export const getPokemon = async (
|
||||
name: string | undefined,
|
||||
): Promise<Pokemon | null> => {
|
||||
if (!name) return null;
|
||||
const {
|
||||
data: { pokemon },
|
||||
} = await client.query(pokemonQuery, { name }).toPromise()
|
||||
} = await client.query(pokemonQuery, { name }).toPromise();
|
||||
|
||||
return pokemon
|
||||
}
|
||||
return pokemon;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Pokemon } from '../types/pokemon';
|
||||
import { client } from './client'
|
||||
import { client } from './client';
|
||||
|
||||
const firstTwentyPokemonsQuery = `
|
||||
query firstTwentyPokemons {
|
||||
@@ -8,15 +8,15 @@ const firstTwentyPokemonsQuery = `
|
||||
name
|
||||
}
|
||||
}
|
||||
`
|
||||
`;
|
||||
|
||||
export const getPokemons = async (): Promise<Array<Pokemon>> => {
|
||||
const {
|
||||
data: { pokemons },
|
||||
} = await client.query(firstTwentyPokemonsQuery).toPromise()
|
||||
} = await client.query(firstTwentyPokemonsQuery).toPromise();
|
||||
|
||||
return pokemons.map((pokemon: Pokemon) => ({
|
||||
...pokemon,
|
||||
name: pokemon.name.toLowerCase(),
|
||||
}))
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
export type Pokemon = { name: string, image: string }
|
||||
export type Pokemon = { name: string; image: string };
|
||||
|
||||
Reference in New Issue
Block a user