BEGIN; SELECT plan(12); SELECT has_table('seasons'); SELECT columns_are('seasons', ARRAY[ 'season_id', 'league_id', 'started_at', 'ended_at', 'created_at', 'modified_at']); SELECT has_sequence('seasons_season_id_seq'); SELECT has_index('teamdraft', 'seasons', 'seasons_pk', 'season_id'); SELECT league_id AS nfl_league_id FROM leagues WHERE name = 'NFL' LIMIT 1 \gset SELECT create_season(:nfl_league_id, now() - interval '1 day', now() + interval '3 months') new_season_id \gset SELECT is(1, (SELECT count(1)::int FROM seasons WHERE season_id = :new_season_id)); SELECT is(:new_season_id, (SELECT current_season_id(:nfl_league_id))); -- rankings SELECT has_table('rankings'); SELECT columns_are('rankings', ARRAY[ 'ranking_id', 'season_id', 'team_id', 'rank', 'created_at', 'modified_at']); SELECT has_sequence('rankings_ranking_id_seq'); SELECT has_index('teamdraft', 'rankings', 'rankings_pk', 'ranking_id primary key'); SELECT is((SELECT count(1) FROM teams JOIN league_divisions USING(league_division_id) WHERE league_id = :nfl_league_id), (SELECT count(1)::bigint FROM current_rankings WHERE season_id = :new_season_id)); SELECT results_eq('SELECT season_id, league_id, name FROM current_rankings WHERE season_id = current_season_id(' || :'nfl_league_id' || ') ORDER BY rank LIMIT 2', 'VALUES (' || :'new_season_id' || ',' || :'nfl_league_id' || $$, 'Buffalo'), ($$ || :'new_season_id' || ',' || :'nfl_league_id' || $$, 'Miami')$$, 'current nfl season rankings'); SELECT * FROM finish(); ROLLBACK;