\set database_name teamdraft
\set schema :database_name
\set rw_name :database_name '_website'
\c :database_name
SET ROLE :rw_name;
SET search_path TO :schema, public;

begin;
do
$$
declare
 player_1_user_id int;
 player_2_user_id int;
 new_league_id int;
 new_draft_id int;
 new_league_season_id int;
begin

INSERT INTO seasons (started_at, ended_at) VALUES (NOW(), NOW() + interval '3 months');

INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 1, 1);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 2, 2);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 3, 3);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 4, 4);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 5, 5);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 6, 6);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 7, 7);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 8, 8);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 9, 9);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 10, 10);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 11, 11);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 12, 12);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 13, 13);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 14, 14);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 15, 15);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 16, 16);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 17, 17);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 18, 18);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 19, 19);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 20, 20);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 21, 21);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 22, 22);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 23, 23);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 24, 24);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 25, 25);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 26, 26);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 27, 27);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 28, 28);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 29, 29);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 30, 30);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 31, 31);
INSERT INTO rankings (season_id, team_id, rank) VALUES (current_season(), 32, 32);

INSERT INTO users (username, name) VALUES ('kent', 'Kent') RETURNING user_id INTO player_1_user_id;
INSERT INTO users (username, name) VALUES ('miranda', 'Miranda') RETURNING user_id INTO player_2_user_id;

INSERT INTO leagues (name, user_id) VALUES ('my league', player_1_user_id) RETURNING league_id INTO new_league_id;
INSERT INTO league_seasons (season_id, league_id) VALUES (current_season(), new_league_id) RETURNING league_season_id INTO new_league_season_id;

INSERT INTO league_users (league_season_id, user_id) VALUES (new_league_season_id, player_1_user_id);
INSERT INTO league_users (league_season_id, user_id) VALUES (new_league_season_id, player_2_user_id);

INSERT INTO drafts (league_season_id, started_at) VALUES (new_league_season_id, NOW()) RETURNING draft_id INTO new_draft_id;

end;

$$;
commit;
