Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move values into configuration settings, stop checking # of slots, use the same magic event ids #162

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

evoskamp
Copy link
Collaborator

Move values into configuration settings, stop checking # of slots, use the same magic event ids

Resolves: #155, #158, #160, #161, #159

Try and bring ACNW and ACUS closer together and clean up common code through:

  1. Configuration values
  2. Use the same magic values for events in the database.
  3. Check directly against configuration.abbr === 'acus' or 'acnw'

Instead of sticking configuration.abbr in local variables of acnw and
acus, which are essentially inverted Boolean flags, check against its
values of 'acus' or 'acnw' directly. It's simpler, clearer, and allows
for adding a third (even if only synthetic) site.

Note, you must add these configuration settings for the deploy to succeed:

Copyright holder in footer

  • config.copyright (string)

Used to set range on min and max player in creating games

  • config.playerMin (positive integer)
  • config.playerMax (positive integer)
  • config.minPlayersFloor (positive integer)
  • config.minPlayersCeiling (positive integer)
  • config.maxPlayersFloor (positive integer)
  • config.maxPlayersCeiling (positive integer)

Used by ACUS only (soon) on its hotel page to allow people to book in its
block of rooms:

  • config.hotelBookingCode (string)
  • config.hotelBookingUrl (string)
  • config.hotelBookingLastdate (date)

To fix the SQL in the ACUS database to ACNW event ids, I run the following
SQL to commit these atrocities:

CREATE OR REPLACE PROCEDURE change_game_id(
   source_game_id INT,
   target_game_id INT
)
LANGUAGE plpgsql    
AS $$
BEGIN
    -- clean out the target
    DELETE FROM game_choice WHERE game_id = target_game_id;
    DELETE FROM game_assignment WHERE game_id = target_game_id;
    DELETE FROM game WHERE id = target_game_id;

    -- clone soure game to target
    INSERT INTO game (id, late_finish, player_max, player_min, room_id, slot_id, players_contact_gm, slot_preference, teen_friendly, "year", author_id, "full", game_contact_email, genre, gm_names, message, description, player_preference, late_start, name, "type", returning_players, setting, short_name, slot_conflicts, char_instructions, estimated_length) SELECT target_game_id, late_finish, player_max, player_min, room_id, slot_id, players_contact_gm, slot_preference, teen_friendly, "year", author_id, "full", game_contact_email, genre, gm_names, message, description, player_preference, late_start, name, "type", returning_players, setting, short_name, slot_conflicts, char_instructions, estimated_length FROM game WHERE id = source_game_id;
     -- update dependencies
    UPDATE game_choice SET game_id = target_game_id WHERE game_id = source_game_id;
    UPDATE game_assignment SET game_id = target_game_id WHERE game_id = source_game_id;
     -- remove cloned game
    DELETE FROM game WHERE id = source_game_id;

    COMMIT;
END;$$


CREATE OR REPLACE PROCEDURE swap_game_ids(
   game_id_a INT,
   game_id_b INT
)
LANGUAGE plpgsql    
AS $$
BEGIN
	-- swap 'em through id = -1 as a buffer
    CALL change_game_id(game_id_a, -1);
    CALL change_game_id(game_id_b, game_id_a);
    CALL change_game_id(-1, game_id_b);

    COMMIT;
END;$$


-- any game
SELECT * FROM game WHERE id IN (144,604);
SELECT game_id, COUNT(*) AS "game_choice" FROM game_choice WHERE game_id IN (144,604) GROUP BY game_id;
SELECT game_id, COUNT(*) AS "game_assignment" FROM game_assignment WHERE game_id IN (144,604) GROUP BY game_id;

CALL swap_game_ids( 144, 604);

SELECT * FROM game WHERE id IN (144,604);
SELECT game_id, COUNT(*) AS "game_choice" FROM game_choice WHERE game_id IN (144,604) GROUP BY game_id;
SELECT game_id, COUNT(*) AS "game_assignment" FROM game_assignment WHERE game_id IN (144,604) GROUP BY game_id;

-- no game in slot x
CALL swap_game_ids( 596, 1);
CALL swap_game_ids( 597, 2);
CALL swap_game_ids( 598, 3);
CALL swap_game_ids( 599, 4);
CALL swap_game_ids( 600, 5);
CALL swap_game_ids( 601, 6);
CALL swap_game_ids( 602, 7);
CALL swap_game_ids( 603, 8);

DROP PROCEDURE IF EXISTS swap_game_ids;

DROP PROCEDURE IF EXISTS change_game_id;

Try and bring ACNW and ACUS together through:
 1. Configuration values
 2.

Added configuration settings:

Copyright holder in footer
 - config.copyright (string)

Used to set range on min and max player in creating games
 - config.playerMin (positive integer)
 - config.playerMax (positive integer)
 - config.minPlayersFloor (positive integer)
 - config.minPlayersCeiling (positive integer)
 - config.maxPlayersFloor (positive integer)
 - config.maxPlayersCeiling (positive integer)

Used by ACUS on its hotel page to allow people to book in its
block of rooms:
 - config.hotelBookingCode (string)
 - config.hotelBookingUrl (string)
 - config.hotelBookingLastdate (date)

Resolves: #155, #158, #160, #161
See also: #159
Instead of sticking configuration.abbr in local variables of acnw and
acus, which are essentially inverted Boolean flags, check against its
values of 'acus' or 'acnw' directly. It's simpler, clearer, and allows
for adding a third (even if only synthetic) site.

Resolves: #155, #158, #160, #161
See also: #159
Copy link

vercel bot commented Jan 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
amber-acus ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2024 4:23am
amberconnw ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2024 4:23am

Wanted to pick up hotel booking code and link and book by date, as
we change those apparently every year. And also wanted to pick up
the contact email from settings.

Resolves: #163, #155, #158, #160, #161, #159
Part of the changes. Guy's PR review noted to remove this.

Don't know how it survived in here with all the other changes to
config in the past, but it's a good thing to make it gone.
@evoskamp
Copy link
Collaborator Author

Now ACUS is over I'm going to make a copy of the database and then update the IDs for the magic events to match ACNW's.

@evoskamp
Copy link
Collaborator Author

Changing IDs works fine. ACNW has a game in game.id = 8, but that's not a big deal as we can use 1-numberOfSlots and 144 (for Any Game).

Since it doesn't matter, if we wanted to make it clean(er), we could move "Any Game" to 0 for ACNW and ACUS.

@evoskamp evoskamp added enhancement New feature or request Core Shared issues labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment