fleet/server/datastore/mysql/migrations/tables/20210601000002_AddRolesToInvites.go
Zach Wasserman 6249beb465
Reorder migrations for pre-4.0 upgrades (#1114)
Reorder migrations from the long-running `teams` branch to ensure that
they can run successfully for deployments upgrading from a pre-4.0
release.

All migrations from the `teams` branch are reordered to take place
_after_ all migrations from the `main` branch, using `20210601` as the
new date, after the latest released `main` branch migration on `20210526`.

Fixes #1058
2021-06-16 11:58:00 -07:00

37 lines
915 B
Go

package tables
import (
"database/sql"
"github.com/pkg/errors"
)
func init() {
MigrationClient.AddMigration(Up_20210601000002, Down_20210601000002)
}
func Up_20210601000002(tx *sql.Tx) error {
// Invites <> Teams mapping
if _, err := tx.Exec(`CREATE TABLE IF NOT EXISTS invite_teams (
invite_id INT UNSIGNED NOT NULL,
team_id INT UNSIGNED NOT NULL,
role VARCHAR(64) NOT NULL,
PRIMARY KEY (invite_id, team_id),
FOREIGN KEY fk_invite_id (invite_id) REFERENCES invites (id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY fk_team_id (team_id) REFERENCES teams (id) ON DELETE CASCADE ON UPDATE CASCADE
)`); err != nil {
return errors.Wrap(err, "create invite_teams")
}
if _, err := tx.Exec(`ALTER TABLE invites
ADD global_role VARCHAR(64) DEFAULT NULL
`); err != nil {
return errors.Wrap(err, "alter users")
}
return nil
}
func Down_20210601000002(tx *sql.Tx) error {
return nil
}