From 9e7d46f08153130577126211cc1767dd9134c98c Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 31 Aug 2024 05:01:15 +0200 Subject: [PATCH] Added API keys table. --- migrations/20240830234355_api_keys.js | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migrations/20240830234355_api_keys.js diff --git a/migrations/20240830234355_api_keys.js b/migrations/20240830234355_api_keys.js new file mode 100644 index 00000000..b649930f --- /dev/null +++ b/migrations/20240830234355_api_keys.js @@ -0,0 +1,28 @@ +exports.up = async (knex) => { + await knex.schema.createTable('users_keys', (table) => { + table.increments('id'); + + table.integer('user_id') + .notNullable() + .references('id') + .inTable('users'); + + table.text('key') + .notNullable(); + + table.string('identifier'); + + table.unique(['user_id', 'identifier']); + + table.datetime('last_used_at'); + table.specificType('last_used_ip', 'inet'); + + table.datetime('created_at') + .notNullable() + .defaultTo(knex.fn.now()); + }); +}; + +exports.down = async (knex) => { + await knex.schema.dropTable('users_keys'); +};