'use strict';

exports.up = async function(db) {
    await db.runSql(`
        CREATE TABLE IF NOT EXISTS passkeys(
            id VARCHAR(128) NOT NULL UNIQUE,
            userId VARCHAR(128) NOT NULL,
            credentialId VARCHAR(512) NOT NULL UNIQUE,
            publicKey TEXT NOT NULL,
            counter BIGINT DEFAULT 0,
            transports TEXT,
            name VARCHAR(128) DEFAULT "",
            creationTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
            lastUsedTime TIMESTAMP NULL,
            FOREIGN KEY(userId) REFERENCES users(id),
            PRIMARY KEY(id)
        ) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
    `);
};

exports.down = async function(db) {
    await db.runSql('DROP TABLE IF EXISTS passkeys;');
};
