From 5534ff1a45642ee0590410487c5fa8a4bbdfc276 Mon Sep 17 00:00:00 2001 From: Alec LaLonde Date: Wed, 6 Jan 2021 22:08:58 -0700 Subject: [PATCH] Renamed player columns to be consistent snake_case (#262) --- hasura/metadata/tables.yaml | 15 +- .../down.sql | 2 + .../up.sql | 1 + .../down.sql | 8 + .../up.sql | 8 + .../backend/src/handlers/graphql/mutations.ts | 10 +- packages/codegen/customFragments.ts | 2 +- packages/codegen/schema.graphql | 178 +++++++----------- packages/web/components/Player/PlayerTile.tsx | 2 +- .../Player/Section/PlayerMemberships.tsx | 2 +- .../web/components/Setup/SetupPlayerType.tsx | 2 +- .../web/components/Setup/SetupProfile.tsx | 4 +- .../web/components/Setup/SetupTimeZone.tsx | 2 +- packages/web/graphql/fragments.ts | 4 +- packages/web/graphql/getPlayers.ts | 2 +- .../web/graphql/mutations/updateProfile.ts | 3 +- packages/web/utils/dateHelpers.ts | 8 +- 17 files changed, 119 insertions(+), 134 deletions(-) create mode 100644 hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/down.sql create mode 100644 hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/up.sql create mode 100644 hasura/migrations/1609965105543_player_table_consistent_column_names/down.sql create mode 100644 hasura/migrations/1609965105543_player_table_consistent_column_names/up.sql diff --git a/hasura/metadata/tables.yaml b/hasura/metadata/tables.yaml index 33722a93..4dd5e285 100644 --- a/hasura/metadata/tables.yaml +++ b/hasura/metadata/tables.yaml @@ -161,7 +161,7 @@ foreign_key_constraint_on: enneagram - name: playerType using: - foreign_key_constraint_on: playerTypeId + foreign_key_constraint_on: player_type_id array_relationships: - name: Accounts using: @@ -211,13 +211,12 @@ - enneagram - ethereum_address - id - - playerTypeId + - player_type_id - rank - role - - scIdentityId + - sc_identity_id + - total_xp - timezone - - totalXp - - tz - username filter: {} - role: public @@ -229,9 +228,8 @@ - id - rank - role + - total_xp - timezone - - totalXp - - tz - username filter: {} update_permissions: @@ -240,10 +238,9 @@ columns: - availability_hours - enneagram - - playerTypeId + - player_type_id - role - timezone - - tz - username filter: id: diff --git a/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/down.sql b/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/down.sql new file mode 100644 index 00000000..80d887a3 --- /dev/null +++ b/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE "public"."player" ADD COLUMN "timezone" int4; +ALTER TABLE "public"."player" ALTER COLUMN "timezone" DROP NOT NULL; diff --git a/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/up.sql b/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/up.sql new file mode 100644 index 00000000..30d75bff --- /dev/null +++ b/hasura/migrations/1609960864949_alter_table_public_player_drop_column_timezone/up.sql @@ -0,0 +1 @@ +ALTER TABLE "public"."player" DROP COLUMN "timezone" CASCADE; diff --git a/hasura/migrations/1609965105543_player_table_consistent_column_names/down.sql b/hasura/migrations/1609965105543_player_table_consistent_column_names/down.sql new file mode 100644 index 00000000..f8d5cc27 --- /dev/null +++ b/hasura/migrations/1609965105543_player_table_consistent_column_names/down.sql @@ -0,0 +1,8 @@ + +alter table "public"."player" rename column "timezone" to "tz"; + +alter table "public"."player" rename column "player_type_id" to "playerTypeId"; + +alter table "public"."player" rename column "sc_identity_id" to "scIdentityId"; + +alter table "public"."player" rename column "total_xp" to "totalXp"; diff --git a/hasura/migrations/1609965105543_player_table_consistent_column_names/up.sql b/hasura/migrations/1609965105543_player_table_consistent_column_names/up.sql new file mode 100644 index 00000000..8fcc0f27 --- /dev/null +++ b/hasura/migrations/1609965105543_player_table_consistent_column_names/up.sql @@ -0,0 +1,8 @@ + +alter table "public"."player" rename column "totalXp" to "total_xp"; + +alter table "public"."player" rename column "scIdentityId" to "sc_identity_id"; + +alter table "public"."player" rename column "playerTypeId" to "player_type_id"; + +alter table "public"."player" rename column "tz" to "timezone"; diff --git a/packages/backend/src/handlers/graphql/mutations.ts b/packages/backend/src/handlers/graphql/mutations.ts index 1046ed88..0630026b 100644 --- a/packages/backend/src/handlers/graphql/mutations.ts +++ b/packages/backend/src/handlers/graphql/mutations.ts @@ -54,13 +54,13 @@ export const UpdatePlayer = gql` _or: [ { ethereum_address: { _eq: $ethAddress } - scIdentityId: { _eq: $identityId } + sc_identity_id: { _eq: $identityId } } { ethereum_address: { _eq: $ethAddress } username: { _eq: $username } } - { scIdentityId: { _eq: $identityId } } + { sc_identity_id: { _eq: $identityId } } { Accounts: { _and: { type: { _eq: DISCORD }, identifier: { _eq: $discordId } } @@ -70,17 +70,17 @@ export const UpdatePlayer = gql` } _set: { ethereum_address: $ethAddress - scIdentityId: $identityId + sc_identity_id: $identityId username: $username rank: $rank - totalXp: $totalXp + total_xp: $totalXp } ) { affected_rows returning { id ethereum_address - scIdentityId + sc_identity_id username } } diff --git a/packages/codegen/customFragments.ts b/packages/codegen/customFragments.ts index af5423a1..2df80323 100644 --- a/packages/codegen/customFragments.ts +++ b/packages/codegen/customFragments.ts @@ -3,6 +3,6 @@ import gql from 'graphql-tag'; export const Player = gql` fragment Player on player { id - totalXp + total_xp } `; diff --git a/packages/codegen/schema.graphql b/packages/codegen/schema.graphql index fe11914c..573b591a 100644 --- a/packages/codegen/schema.graphql +++ b/packages/codegen/schema.graphql @@ -2499,13 +2499,12 @@ type player { """An object relationship""" playerType: player_type - playerTypeId: Int + player_type_id: Int rank: PlayerRank_enum role: String - scIdentityId: String - timezone: Int - totalXp: numeric - tz: String + sc_identity_id: String + timezone: String + total_xp: numeric updated_at: timestamptz username: String! } @@ -2742,9 +2741,8 @@ input player_arr_rel_insert_input { """aggregate avg on columns""" type player_avg_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -2752,9 +2750,8 @@ order by avg() on columns of table "player" """ input player_avg_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """ @@ -2774,13 +2771,12 @@ input player_bool_exp { guilds: guild_player_bool_exp id: uuid_comparison_exp playerType: player_type_bool_exp - playerTypeId: Int_comparison_exp + player_type_id: Int_comparison_exp rank: PlayerRank_enum_comparison_exp role: String_comparison_exp - scIdentityId: String_comparison_exp - timezone: Int_comparison_exp - totalXp: numeric_comparison_exp - tz: String_comparison_exp + sc_identity_id: String_comparison_exp + timezone: String_comparison_exp + total_xp: numeric_comparison_exp updated_at: timestamptz_comparison_exp username: String_comparison_exp } @@ -2807,9 +2803,8 @@ input type for incrementing integer column in table "player" """ input player_inc_input { availability_hours: Int - playerTypeId: Int - timezone: Int - totalXp: numeric + player_type_id: Int + total_xp: numeric } """ @@ -2826,13 +2821,12 @@ input player_insert_input { guilds: guild_player_arr_rel_insert_input id: uuid playerType: player_type_obj_rel_insert_input - playerTypeId: Int + player_type_id: Int rank: PlayerRank_enum role: String - scIdentityId: String - timezone: Int - totalXp: numeric - tz: String + sc_identity_id: String + timezone: String + total_xp: numeric updated_at: timestamptz username: String } @@ -2843,12 +2837,11 @@ type player_max_fields { created_at: timestamptz ethereum_address: String id: uuid - playerTypeId: Int + player_type_id: Int role: String - scIdentityId: String - timezone: Int - totalXp: numeric - tz: String + sc_identity_id: String + timezone: String + total_xp: numeric updated_at: timestamptz username: String } @@ -2861,12 +2854,11 @@ input player_max_order_by { created_at: order_by ethereum_address: order_by id: order_by - playerTypeId: order_by + player_type_id: order_by role: order_by - scIdentityId: order_by + sc_identity_id: order_by timezone: order_by - totalXp: order_by - tz: order_by + total_xp: order_by updated_at: order_by username: order_by } @@ -2877,12 +2869,11 @@ type player_min_fields { created_at: timestamptz ethereum_address: String id: uuid - playerTypeId: Int + player_type_id: Int role: String - scIdentityId: String - timezone: Int - totalXp: numeric - tz: String + sc_identity_id: String + timezone: String + total_xp: numeric updated_at: timestamptz username: String } @@ -2895,12 +2886,11 @@ input player_min_order_by { created_at: order_by ethereum_address: order_by id: order_by - playerTypeId: order_by + player_type_id: order_by role: order_by - scIdentityId: order_by + sc_identity_id: order_by timezone: order_by - totalXp: order_by - tz: order_by + total_xp: order_by updated_at: order_by username: order_by } @@ -2947,13 +2937,12 @@ input player_order_by { guilds_aggregate: guild_player_aggregate_order_by id: order_by playerType: player_type_order_by - playerTypeId: order_by + player_type_id: order_by rank: order_by role: order_by - scIdentityId: order_by + sc_identity_id: order_by timezone: order_by - totalXp: order_by - tz: order_by + total_xp: order_by updated_at: order_by username: order_by } @@ -2985,7 +2974,7 @@ enum player_select_column { id """column name""" - playerTypeId + player_type_id """column name""" rank @@ -2994,16 +2983,13 @@ enum player_select_column { role """column name""" - scIdentityId + sc_identity_id """column name""" timezone """column name""" - totalXp - - """column name""" - tz + total_xp """column name""" updated_at @@ -3021,13 +3007,12 @@ input player_set_input { enneagram: EnneagramType_enum ethereum_address: String id: uuid - playerTypeId: Int + player_type_id: Int rank: PlayerRank_enum role: String - scIdentityId: String - timezone: Int - totalXp: numeric - tz: String + sc_identity_id: String + timezone: String + total_xp: numeric updated_at: timestamptz username: String } @@ -3211,9 +3196,8 @@ enum player_skill_update_column { """aggregate stddev on columns""" type player_stddev_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3221,17 +3205,15 @@ order by stddev() on columns of table "player" """ input player_stddev_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """aggregate stddev_pop on columns""" type player_stddev_pop_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3239,17 +3221,15 @@ order by stddev_pop() on columns of table "player" """ input player_stddev_pop_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """aggregate stddev_samp on columns""" type player_stddev_samp_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3257,17 +3237,15 @@ order by stddev_samp() on columns of table "player" """ input player_stddev_samp_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """aggregate sum on columns""" type player_sum_fields { availability_hours: Int - playerTypeId: Int - timezone: Int - totalXp: numeric + player_type_id: Int + total_xp: numeric } """ @@ -3275,9 +3253,8 @@ order by sum() on columns of table "player" """ input player_sum_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """ @@ -3622,7 +3599,7 @@ enum player_update_column { id """column name""" - playerTypeId + player_type_id """column name""" rank @@ -3631,16 +3608,13 @@ enum player_update_column { role """column name""" - scIdentityId + sc_identity_id """column name""" timezone """column name""" - totalXp - - """column name""" - tz + total_xp """column name""" updated_at @@ -3652,9 +3626,8 @@ enum player_update_column { """aggregate var_pop on columns""" type player_var_pop_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3662,17 +3635,15 @@ order by var_pop() on columns of table "player" """ input player_var_pop_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """aggregate var_samp on columns""" type player_var_samp_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3680,17 +3651,15 @@ order by var_samp() on columns of table "player" """ input player_var_samp_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """aggregate variance on columns""" type player_variance_fields { availability_hours: Float - playerTypeId: Float - timezone: Float - totalXp: Float + player_type_id: Float + total_xp: Float } """ @@ -3698,9 +3667,8 @@ order by variance() on columns of table "player" """ input player_variance_order_by { availability_hours: order_by - playerTypeId: order_by - timezone: order_by - totalXp: order_by + player_type_id: order_by + total_xp: order_by } """ diff --git a/packages/web/components/Player/PlayerTile.tsx b/packages/web/components/Player/PlayerTile.tsx index 68df244c..cc486a66 100644 --- a/packages/web/components/Player/PlayerTile.tsx +++ b/packages/web/components/Player/PlayerTile.tsx @@ -82,7 +82,7 @@ export const PlayerTile: React.FC = ({ player }) => ( {player.rank} )} - XP: {Math.floor(player.totalXp)} + XP: {Math.floor(player.total_xp)} {player.box_profile?.description ? ( diff --git a/packages/web/components/Player/Section/PlayerMemberships.tsx b/packages/web/components/Player/Section/PlayerMemberships.tsx index 38bab084..ad4114c5 100644 --- a/packages/web/components/Player/Section/PlayerMemberships.tsx +++ b/packages/web/components/Player/Section/PlayerMemberships.tsx @@ -49,7 +49,7 @@ export const PlayerMemberships: React.FC = ({ } {(player.rank || '').toLowerCase()} - XP: {Math.round(player.totalXp || 0)} + XP: {Math.round(player.total_xp || 0)} diff --git a/packages/web/components/Setup/SetupPlayerType.tsx b/packages/web/components/Setup/SetupPlayerType.tsx index b7fb84d8..af60c7bd 100644 --- a/packages/web/components/Setup/SetupPlayerType.tsx +++ b/packages/web/components/Setup/SetupPlayerType.tsx @@ -36,7 +36,7 @@ export const SetupPlayerType: React.FC = () => { playerId: user.id, input: { enneagram: personalityType?.name, - playerTypeId: playerType?.id, + player_type_id: playerType?.id, }, }); diff --git a/packages/web/components/Setup/SetupProfile.tsx b/packages/web/components/Setup/SetupProfile.tsx index a234a427..8c628bd1 100644 --- a/packages/web/components/Setup/SetupProfile.tsx +++ b/packages/web/components/Setup/SetupProfile.tsx @@ -58,8 +58,8 @@ export const SetupProfile: React.FC = () => { })), ); } - if (player.tz && !timeZone) { - setTimeZone(player.tz); + if (player.timezone && !timeZone) { + setTimeZone(player.timezone); } } }, [ diff --git a/packages/web/components/Setup/SetupTimeZone.tsx b/packages/web/components/Setup/SetupTimeZone.tsx index 4fd1835a..335aca5d 100644 --- a/packages/web/components/Setup/SetupTimeZone.tsx +++ b/packages/web/components/Setup/SetupTimeZone.tsx @@ -28,7 +28,7 @@ export const SetupTimeZone: React.FC = () => { const { error } = await updateProfile({ playerId: user.id, input: { - tz: timeZone + timezone: timeZone } }); diff --git a/packages/web/graphql/fragments.ts b/packages/web/graphql/fragments.ts index ac7be5c6..59f011d1 100644 --- a/packages/web/graphql/fragments.ts +++ b/packages/web/graphql/fragments.ts @@ -4,11 +4,11 @@ export const PlayerFragment = gql` fragment PlayerFragment on player { id username - totalXp + total_xp rank ethereum_address availability_hours - tz + timezone EnneagramType { description name diff --git a/packages/web/graphql/getPlayers.ts b/packages/web/graphql/getPlayers.ts index ff32e269..a5253aa9 100644 --- a/packages/web/graphql/getPlayers.ts +++ b/packages/web/graphql/getPlayers.ts @@ -6,7 +6,7 @@ import { PlayerFragment } from './fragments'; const playersQuery = gql` query GetPlayers($limit: Int) { - player(order_by: { totalXp: desc }, limit: $limit) { + player(order_by: { total_xp: desc }, limit: $limit) { ...PlayerFragment } } diff --git a/packages/web/graphql/mutations/updateProfile.ts b/packages/web/graphql/mutations/updateProfile.ts index 4595890c..36f31bfd 100644 --- a/packages/web/graphql/mutations/updateProfile.ts +++ b/packages/web/graphql/mutations/updateProfile.ts @@ -5,7 +5,8 @@ export const UpdateProfileMutation = gql` update_player_by_pk(pk_columns: { id: $playerId }, _set: $input) { id availability_hours - tz + timezone } } `; + \ No newline at end of file diff --git a/packages/web/utils/dateHelpers.ts b/packages/web/utils/dateHelpers.ts index 06bf90df..3f0f786b 100644 --- a/packages/web/utils/dateHelpers.ts +++ b/packages/web/utils/dateHelpers.ts @@ -10,9 +10,9 @@ export interface TimeZoneDisplay { export const getPlayerTimeZoneDisplay = (player: PlayerFragmentFragment): TimeZoneDisplay => { let tzLabel; let offsetLabel; - if (player?.tz) { - const timeZone = spacetime.now().goto(player.tz) - const tzDisplay = display(player.tz) + if (player?.timezone) { + const timeZone = spacetime.now().goto(player.timezone) + const tzDisplay = display(player.timezone) if (tzDisplay && tzDisplay.daylight && tzDisplay.standard) { tzLabel = timeZone.isDST() ? tzDisplay.daylight.abbrev @@ -24,7 +24,7 @@ export const getPlayerTimeZoneDisplay = (player: PlayerFragmentFragment): TimeZo offsetLabel = `(GMT ${offset})`; } } else { - tzLabel = player.tz; + tzLabel = player.timezone; } }