sendou.ink/migrations/069-many-teams.js
Kalle 1c9dcacbf2
Join many teams & front page changelog (#1880)
* Initial

* Progress

* Changelog initial

* Progress

* E2E test
2024-09-14 12:31:05 +03:00

39 lines
1019 B
JavaScript

export function up(db) {
db.transaction(() => {
db.prepare(
/* sql */ `alter table "AllTeamMember" add "isMainTeam" integer default 1`,
).run();
db.prepare(/*sql */ `drop view "TeamMember"`).run();
db.prepare(
/*sql*/ `
create view "TeamMember"
as
select "AllTeamMember".*
from "AllTeamMember"
left join "Team" on "Team"."id" = "AllTeamMember"."teamId"
where "AllTeamMember"."leftAt" is null
and
-- if team id is null the team is deleted
"Team"."id" is not null
and
"AllTeamMember"."isMainTeam" = 1
`,
).run();
db.prepare(
/*sql*/ `
create view "TeamMemberWithSecondary"
as
select "AllTeamMember".*
from "AllTeamMember"
left join "Team" on "Team"."id" = "AllTeamMember"."teamId"
where "AllTeamMember"."leftAt" is null
and
-- if team id is null the team is deleted
"Team"."id" is not null
`,
).run();
})();
}