Skip to content

Commit

Permalink
Refactor stored procedures to use consistent naming conventions for p…
Browse files Browse the repository at this point in the history
…layer, world, city, and building identifiers
  • Loading branch information
Vianpyro committed Nov 12, 2024
1 parent b7117d0 commit fd42439
Showing 1 changed file with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions create_get_procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ DELIMITER //

CREATE PROCEDURE get_all_players()
BEGIN
SELECT id, name, email, gold, created_at, last_login FROM player;
SELECT player_id, player_name, email, gold, created_at, last_login FROM player;
END //

CREATE PROCEDURE get_player_by_id(IN player_id INT)
BEGIN
SELECT id, name, email, gold, created_at, last_login
SELECT player_id, player_name, email, gold, created_at, last_login
FROM player
WHERE id = player_id;
END //

CREATE PROCEDURE get_player_by_name(IN name VARCHAR(100))
CREATE PROCEDURE get_player_by_name(IN player_name VARCHAR(100))
BEGIN
SELECT id, name, email, gold, created_at, last_login
SELECT player_id, player_name, email, gold, created_at, last_login
FROM player
WHERE name = name;
WHERE player_name = player_name;
END //

CREATE PROCEDURE get_player_worlds(IN player_id INT)
BEGIN
SELECT w.id, w.name, w.description, w.created_at
SELECT w.world_id, w.world_name, w.world_description, w.created_at
FROM world w
JOIN player_world pw ON w.id = pw.world_id
JOIN player_world pw ON w.world_id = pw.world_id
WHERE pw.player_id = player_id;
END //

CREATE PROCEDURE get_player_cities(IN player_id INT)
BEGIN
SELECT c.id, c.name, c.x, c.y, c.island_id
SELECT c.city_id, c.city_name, c.x, c.y, c.island_id
FROM city c
WHERE c.owner_id = player_id;
END //
Expand All @@ -43,37 +43,37 @@ END //

CREATE PROCEDURE get_all_worlds()
BEGIN
SELECT id, name, description, seed, action_speed, unit_speed, trade_speed, night_bonus,
BEGINNER_PROTECTION, MORALE, ALLIANCE_CAP, STATUS, created_at
SELECT world_id, world_name, world_description, seed, action_speed, unit_speed, trade_speed,
night_bonus, beginner_protection, morale, alliance_cap, world_status, created_at
FROM world;
END //

CREATE PROCEDURE get_world_by_id(IN world_id INT)
BEGIN
SELECT id, name, description, seed, action_speed, unit_speed, trade_speed, night_bonus,
BEGINNER_PROTECTION, MORALE, ALLIANCE_CAP, STATUS, created_at
SELECT world_id, world_name, world_description, seed, action_speed, unit_speed, trade_speed,
night_bonus, beginner_protection, morale, alliance_cap, world_status, created_at
FROM world
WHERE id = world_id;
WHERE world_id = world_id;
END //

CREATE PROCEDURE get_active_worlds()
BEGIN
SELECT id, name, description, created_at
SELECT world_id, world_name, world_description, created_at
FROM world
WHERE STATUS = 1;
END //

CREATE PROCEDURE get_players_in_world(IN world_id INT)
BEGIN
SELECT p.id, p.name, p.email, p.gold, p.created_at
SELECT p.player_id, p.player_name, p.email, p.gold, p.created_at
FROM player p
JOIN player_world pw ON p.id = pw.player_id
JOIN player_world pw ON p.player_id = pw.player_id
WHERE pw.world_id = world_id;
END //

CREATE PROCEDURE get_world_islands(IN world_id INT)
BEGIN
SELECT id, x, y
SELECT island_id, x, y
FROM island
WHERE world_id = world_id;
END //
Expand All @@ -82,20 +82,20 @@ END //

CREATE PROCEDURE get_all_islands()
BEGIN
SELECT id, x, y, world_id
SELECT island_id, x, y, world_id
FROM island;
END //

CREATE PROCEDURE get_island_by_id(IN island_id INT)
BEGIN
SELECT id, x, y, world_id
SELECT island_id, x, y, world_id
FROM island
WHERE id = island_id;
WHERE island_id = island_id;
END //

CREATE PROCEDURE get_island_cities(IN island_id INT)
BEGIN
SELECT id, name, x, y, owner_id
SELECT city_id, city_name, x, y, owner_id
FROM city
WHERE island_id = island_id;
END //
Expand All @@ -104,43 +104,43 @@ END //

CREATE PROCEDURE get_all_cities()
BEGIN
SELECT id, name, x, y, island_id, owner_id
SELECT city_id, city_name, x, y, island_id, owner_id
FROM city;
END //

CREATE PROCEDURE get_city_by_id(IN city_id INT)
BEGIN
SELECT id, name, x, y, island_id, owner_id
SELECT city_id, city_name, x, y, island_id, owner_id
FROM city
WHERE id = city_id;
END //

CREATE PROCEDURE get_cities_in_world(IN world_id INT)
BEGIN
SELECT c.id, c.name, c.x, c.y, c.owner_id, c.island_id
SELECT c.city_id, c.city_name, c.x, c.y, c.owner_id, c.island_id
FROM city c
JOIN island i ON c.island_id = i.id
JOIN island i ON c.island_id = i.island_id
WHERE i.world_id = world_id;
END //

-- Building Procedures

CREATE PROCEDURE get_all_buildings()
BEGIN
SELECT id, name, level, max_level, city_id
SELECT building_id, building_name, building_level, max_level, city_id
FROM building;
END //

CREATE PROCEDURE get_city_buildings(IN city_id INT)
BEGIN
SELECT id, name, level, max_level
SELECT building_id, building_name, building_level, max_level
FROM building
WHERE city_id = city_id;
END //

CREATE PROCEDURE get_building_by_id(IN building_id INT)
BEGIN
SELECT id, name, level, max_level, city_id
SELECT building_id, building_name, building_level, max_level, city_id
FROM building
WHERE id = building_id;
END //
Expand All @@ -156,23 +156,25 @@ END //

CREATE PROCEDURE get_all_units()
BEGIN
SELECT id, name, description, type, wood_cost, stone_cost, silver_cost, population_cost,
training_time, damage, defense_blunt, defense_distance, defense_sharp, speed, can_fly
SELECT unit_id, unit_name, unit_description, unit_type, wood_cost, stone_cost, silver_cost,
population_cost, training_time, damage, defense_blunt, defense_distance, defense_sharp,
speed, can_fly
FROM unit;
END //

CREATE PROCEDURE get_city_units(IN city_id INT)
BEGIN
SELECT u.id, u.name, cu.quantity
SELECT u.unit_id, u.unit_name, cu.quantity
FROM unit u
JOIN city_unit cu ON u.id = cu.unit_id
JOIN city_unit cu ON u.unit_id = cu.unit_id
WHERE cu.city_id = city_id;
END //

CREATE PROCEDURE get_unit_by_id(IN unit_id INT)
BEGIN
SELECT id, name, description, type, wood_cost, stone_cost, silver_cost, population_cost,
training_time, damage, defense_blunt, defense_distance, defense_sharp, speed, can_fly
SELECT unit_id, unit_name, unit_description, unit_type, wood_cost, stone_cost, silver_cost,
population_cost, training_time, damage, defense_blunt, defense_distance, defense_sharp,
speed, can_fly
FROM unit
WHERE id = unit_id;
END //
Expand All @@ -181,20 +183,23 @@ END //

CREATE PROCEDURE get_all_battles()
BEGIN
SELECT id, attacker_id, defender_id, time, winner_id, loser_id, loot_wood, loot_stone, loot_silver
SELECT battle_id, attacker_id, defender_id, battle_time, winner_id, loser_id, loot_wood,
loot_stone, loot_silver
FROM battle;
END //

CREATE PROCEDURE get_battle_by_id(IN battle_id INT)
BEGIN
SELECT id, attacker_id, defender_id, time, winner_id, loser_id, loot_wood, loot_stone, loot_silver
SELECT battle_id, attacker_id, defender_id, battle_time, winner_id, loser_id, loot_wood,
loot_stone, loot_silver
FROM battle
WHERE id = battle_id;
END //

CREATE PROCEDURE get_player_battles(IN player_id INT)
BEGIN
SELECT id, attacker_id, defender_id, time, winner_id, loser_id, loot_wood, loot_stone, loot_silver
SELECT battle_id, attacker_id, defender_id, battle_time, winner_id, loser_id, loot_wood,
loot_stone, loot_silver
FROM battle
WHERE attacker_id = player_id OR defender_id = player_id;
END //
Expand All @@ -210,7 +215,7 @@ END //

CREATE PROCEDURE get_building_requirements(IN building_id INT)
BEGIN
SELECT wood, stone, silver, population
SELECT required_wood, required_stone, required_silver, required_population
FROM building_requirement
WHERE building_id = building_id;
END //
Expand Down

0 comments on commit fd42439

Please sign in to comment.