Skip to content

Commit

Permalink
SQL: Add Migrations to CI and also break schema into smaller files (#27)
Browse files Browse the repository at this point in the history
* ci: fix migrations, lots of typos, non-unique fks, add first modeling for spells and projectiles + check migrations in CI

---------

Co-authored-by: EduardoLR10 <[email protected]>
  • Loading branch information
mtrsk and EduardoLR10 authored Oct 15, 2024
1 parent 14d978f commit 81768f6
Show file tree
Hide file tree
Showing 14 changed files with 514 additions and 237 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ jobs:
env:
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
POSTGRES_USER: ${{ env.PGUSER }}
POSTGRES_DATABASE: ${{ env.PGDATABASE }}
POSTGRES_DB: ${{ env.PGDATABASE }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-timeout 10s
--health-retries 5
ports:
- 5432:5432
Expand All @@ -68,10 +68,14 @@ jobs:
- name: Install Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@main

- name: "[Server] build"
- name: "[Server] Build"
run: |
nix build .#server
- name: "[Server] tests"
- name: "[Server] Tests"
run: |
nix develop .#ci --impure -c just test
- name: "[Server] Check Migrations"
run: |
nix develop .#ci --impure -c just db-up
2 changes: 2 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Then simply interact with ~/localhost:8080/~. For more commands, make sure to ch
just
#+END_SRC

to migrate the local dababase, you can use ~just db-up~ or ~db-up~.

*** Nix Builds

You can also build the server and related OCI images with Nix.
Expand Down
14 changes: 10 additions & 4 deletions database/main.input.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ VALUES ('Huneric', '[email protected]', 'mmagueta'),
('Gaiseric', '[email protected]', 'mmagueta'),
('Legion', '[email protected]', 'lambdu');

INSERT INTO lyceum.character_stats (name, e_mail, username, constitution, wisdom, strength, endurance, intelligence, faith)
VALUES ('Huneric', '[email protected]', 'mmagueta', 100, 110, 95, 120, 105, 100),
('Gaiseric', '[email protected]', 'mmagueta', 60, 110, 55, 150, 150, 50),
('Legion', '[email protected]', 'lambdu', 60, 110, 55, 150, 150, 50);
INSERT INTO lyceum.character_stats (name, e_mail, username, constitution, wisdom, strength, endurance, intelligence, faith, mana, health)
VALUES ('Huneric', '[email protected]', 'mmagueta', 100, 110, 95, 120, 105, 100, 100, 100),
('Gaiseric', '[email protected]', 'mmagueta', 60, 110, 55, 150, 150, 50, 100, 100),
('Legion', '[email protected]', 'lambdu', 60, 110, 55, 150, 150, 50, 100, 100);

INSERT INTO lyceum.character_position (name, e_mail, username, x_position, y_position, map_name, face_direction)
VALUES ('Huneric', '[email protected]', 'mmagueta', 10, 20, 'CASTLE_HALL', 270),
Expand All @@ -35,3 +35,9 @@ VALUES ('Huneric', '[email protected]', 'mmagueta', true, 'Vandal''s Prima',
('Huneric', '[email protected]', 'mmagueta', true, 'Blood-Reaver''s Gauntlet', 'ARMS'::lyceum.equipment_use, 'ARMS'::lyceum.equipment_kind),
('Gaiseric', '[email protected]', 'mmagueta', true, 'Vandal''s Prima', 'RIGHT_ARM', 'ARMS'::lyceum.equipment_kind),
('Legion', '[email protected]', 'lambdu', true, 'Vandal''s Prima', 'RIGHT_ARM', 'ARMS'::lyceum.equipment_kind);

-- Insert into lyceum.view_spell_destruction
INSERT INTO lyceum.view_spell_destruction (name, description, cost, duration, cast_time, kind, target, base_damage, damage_kind, destruction_kind)
VALUES ('Fire Ball', 'Something cool', 10, 50, 1, 'PROJECTILE'::lyceum.spell_type, 'SINGULAR'::lyceum.spell_target, 100, 'FIRE'::lyceum.spell_damage_type, 'MAGIC'::lyceum.spell_destruction_type),
('Ice Ball', 'Another cool thing', 10, 50, 1, 'PROJECTILE'::lyceum.spell_type, 'SINGULAR'::lyceum.spell_target, 100, 'FIRE'::lyceum.spell_damage_type, 'MAGIC'::lyceum.spell_destruction_type);

1 change: 1 addition & 0 deletions database/migrations/000001_schemas.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE SCHEMA IF NOT EXISTS lyceum;
228 changes: 0 additions & 228 deletions database/migrations/000001_setup.sql

This file was deleted.

53 changes: 53 additions & 0 deletions database/migrations/000002_lyceum_world.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- Defines:
-- Tile Types
-- Map
-- Objects

CREATE TYPE lyceum.TILE_TYPE AS ENUM(
'WATER',
'GRASS',
'SAND',
'ROCK'
);

CREATE TABLE lyceum.map(
name VARCHAR(16) NOT NULL,
PRIMARY KEY(name)
);

CREATE TABLE lyceum.tile(
map_name VARCHAR(16) NOT NULL,
kind lyceum.TILE_TYPE NOT NULL,
x_position SMALLINT NOT NULL,
y_position SMALLINT NOT NULL,
PRIMARY KEY(map_name, kind, x_position, y_position),
FOREIGN KEY (map_name) REFERENCES lyceum.map(name)
);

CREATE TABLE lyceum.object(
map_name VARCHAR(16) NOT NULL,
name VARCHAR(16) NOT NULL,
x_position SMALLINT NOT NULL,
y_position SMALLINT NOT NULL,
PRIMARY KEY(map_name, x_position, y_position),
FOREIGN KEY (map_name) REFERENCES lyceum.map(name)
);

CREATE OR REPLACE FUNCTION map_object_overlap() RETURNS trigger AS $map_object_overlap$
DECLARE
kind TEXT;
BEGIN
SELECT kind INTO kind FROM tile WHERE x_position = NEW.x_position AND y_position = NEW.y_position;

IF NEW.name = 'TREE' THEN
IF kind <> 'GRASS' AND kind <> 'SAND' THEN
RAISE EXCEPTION '''TREE'' cannot be defined in tiles that are not ''GRASS'' or ''SAND''.';
END IF;
END IF;

RETURN NEW;
END;
$map_object_overlap$ LANGUAGE plpgsql;

CREATE TRIGGER map_object_overlap BEFORE INSERT OR UPDATE ON lyceum.object
FOR EACH ROW EXECUTE FUNCTION map_object_overlap();
Loading

0 comments on commit 81768f6

Please sign in to comment.