diff --git a/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.all.down.sql b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.all.down.sql deleted file mode 100644 index e69de29bb..000000000 diff --git a/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.mysql.down.sql b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.mysql.down.sql new file mode 100644 index 000000000..d112de6b2 --- /dev/null +++ b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.mysql.down.sql @@ -0,0 +1,31 @@ +ALTER TABLE webauthn_devices + RENAME _bkp_DOWN_V0008_webauthn_devices; + +CREATE TABLE IF NOT EXISTS webauthn_devices ( + id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_used_at TIMESTAMP NULL DEFAULT NULL, + rpid TEXT, + username VARCHAR(100) NOT NULL, + description VARCHAR(30) NOT NULL DEFAULT 'Primary', + kid VARCHAR(512) NOT NULL, + public_key BLOB NOT NULL, + attestation_type VARCHAR(32), + transport VARCHAR(20) DEFAULT '', + aaguid CHAR(36) NOT NULL, + sign_count INTEGER DEFAULT 0, + clone_warning BOOLEAN NOT NULL DEFAULT FALSE, + UNIQUE KEY (username, description), + UNIQUE KEY (kid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; + +CREATE UNIQUE INDEX webauthn_devices_kid_key ON webauthn_devices (kid); +CREATE UNIQUE INDEX webauthn_devices_lookup_key ON webauthn_devices (rpid, username, description); + +INSERT INTO webauthn_devices (created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning) +SELECT created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning +FROM _bkp_DOWN_V0008_webauthn_devices +WHERE legacy = TRUE; + +DROP TABLE IF EXISTS _bkp_DOWN_V0008_webauthn_devices; +DROP TABLE IF EXISTS webauthn_users; diff --git a/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.postgres.down.sql b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.postgres.down.sql new file mode 100644 index 000000000..32e5916ea --- /dev/null +++ b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.postgres.down.sql @@ -0,0 +1,36 @@ +ALTER TABLE webauthn_devices + DROP CONSTRAINT IF EXISTS webauthn_devices_pkey; + +DROP INDEX IF EXISTS webauthn_devices_pkey; +DROP INDEX IF EXISTS webauthn_devices_kid_key; +DROP INDEX IF EXISTS webauthn_devices_lookup_key; + +ALTER TABLE webauthn_devices + RENAME TO _bkp_DOWN_V0008_webauthn_devices; + +CREATE TABLE IF NOT EXISTS webauthn_devices ( + id SERIAL CONSTRAINT webauthn_devices_pkey PRIMARY KEY, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_used_at TIMESTAMP WITH TIME ZONE NULL DEFAULT NULL, + rpid TEXT, + username VARCHAR(100) NOT NULL, + description VARCHAR(30) NOT NULL DEFAULT 'Primary', + kid VARCHAR(512) NOT NULL, + public_key BYTEA NOT NULL, + attestation_type VARCHAR(32), + transport VARCHAR(20) DEFAULT '', + aaguid CHAR(36) NOT NULL, + sign_count INTEGER DEFAULT 0, + clone_warning BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE UNIQUE INDEX webauthn_devices_kid_key ON webauthn_devices (kid); +CREATE UNIQUE INDEX webauthn_devices_lookup_key ON webauthn_devices (username, description); + +INSERT INTO webauthn_devices (created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning) +SELECT created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning +FROM _bkp_DOWN_V0008_webauthn_devices +WHERE legacy = TRUE; + +DROP TABLE IF EXISTS _bkp_DOWN_V0008_webauthn_devices; +DROP TABLE IF EXISTS webauthn_users; diff --git a/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.sqlite.down.sql b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.sqlite.down.sql new file mode 100644 index 000000000..63102d931 --- /dev/null +++ b/internal/storage/migrations/V0008.WebauthnMultiCookieDomain.sqlite.down.sql @@ -0,0 +1,29 @@ +ALTER TABLE webauthn_devices + RENAME TO _bkp_DOWN_V0008_webauthn_devices; + +CREATE TABLE IF NOT EXISTS webauthn_devices ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + last_used_at DATETIME NULL DEFAULT NULL, + rpid TEXT, + username VARCHAR(100) NOT NULL, + description VARCHAR(30) NOT NULL DEFAULT 'Primary', + kid VARCHAR(512) NOT NULL, + public_key BLOB NOT NULL, + attestation_type VARCHAR(32), + transport VARCHAR(20) DEFAULT '', + aaguid CHAR(36) NULL, + sign_count INTEGER DEFAULT 0, + clone_warning BOOLEAN NOT NULL DEFAULT FALSE +); + +CREATE UNIQUE INDEX webauthn_devices_lookup_key ON webauthn_devices (username, description); +CREATE UNIQUE INDEX webauthn_devices_kid_key ON webauthn_devices (kid); + +INSERT INTO webauthn_devices (created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning) +SELECT created_at, last_used_at, rpid, username, description, kid, public_key, attestation_type, transport, aaguid, sign_count, clone_warning +FROM _bkp_DOWN_V0008_webauthn_devices +WHERE legacy = TRUE; + +DROP TABLE IF EXISTS _bkp_DOWN_V0008_webauthn_devices; +DROP TABLE IF EXISTS webauthn_users;