Files
speckle-server/packages/server/modules/auth/migrations/2020-05-29-apps.js
T
Kristaps Fabians Geikins bde148f286 chore(server): migrating fully to ESM (#5042)
* wip

* some extra fixes

* stuff kinda works?

* need to figure out mocks

* need to figure out mocks

* fix db listener

* gqlgen fix

* minor gqlgen watch adjustment

* lint fixes

* delete old codegen file

* converting migrations to ESM

* getModuleDIrectory

* vitest sort of works

* added back ts-vitest

* resolve gql double load

* fixing test timeout configs

* TSC lint fix

* fix automate tests

* moar debugging

* debugging

* more debugging

* codegen update

* server works

* yargs migrated

* chore(server): getting rid of global mocks for Server ESM (#5046)

* got rid of email mock

* got rid of comment mocks

* got rid of multi region mocks

* got rid of stripe mock

* admin override mock updated

* removed final mock

* fixing import.meta.resolve calls

* another import.meta.resolve fix

* added requested test

* nyc ESM fix

* removed unneeded deps + linting

* yarn lock forgot to commit

* tryna fix flakyness

* email capture util fix

* sendEmail fix

* fix TSX check

* sender transporter fix + CR comments

* merge main fix

* test fixx

* circleci fix

* gqlgen bigint fix

* error formatter fix

* more error formatting improvements

* esmloader added to Dockerfile

* more dockerfile fixes

* bg jobs fix
2025-07-14 10:26:19 +03:00

106 lines
3.1 KiB
JavaScript

/* istanbul ignore file */
'use strict'
// Knex table migrations
const up = async (knex) => {
// Applications that integrate with this server.
await knex.schema.createTable('server_apps', (table) => {
table.string('id', 10).primary()
table.string('secret', 10)
table.string('name', 256).notNullable()
table.string('description', 512)
table.string('termsAndConditionsLink', 256)
table.string('logo', 524288)
table.boolean('public').defaultTo(false)
table.boolean('trustByDefault').defaultTo(false)
table.string('authorId').references('id').inTable('users').onDelete('cascade')
table.timestamp('createdAt').defaultTo(knex.fn.now())
table.string('redirectUrl', 100).notNullable()
})
// Tracks which scopes are available to each individual app.
await knex.schema.createTable('server_apps_scopes', (table) => {
table
.string('appId')
.references('id')
.inTable('server_apps')
.notNullable()
.onDelete('cascade')
.index()
table
.string('scopeName')
.references('name')
.inTable('scopes')
.notNullable()
.onDelete('cascade')
.index()
})
await knex.schema.createTable('authorization_codes', (table) => {
table.string('id').primary()
table.string('appId').references('id').inTable('server_apps').onDelete('cascade')
table.string('userId').references('id').inTable('users').onDelete('cascade')
table.string('challenge').notNullable()
table.timestamp('createdAt').defaultTo(knex.fn.now())
table.bigint('lifespan').defaultTo(6e5) // 10 minutes
})
await knex.schema.createTable('refresh_tokens', (table) => {
table.string('id').primary()
table.string('tokenDigest').notNullable()
table.string('appId').references('id').inTable('server_apps').onDelete('cascade')
table.string('userId').references('id').inTable('users').onDelete('cascade')
table.timestamp('createdAt').defaultTo(knex.fn.now())
table.bigint('lifespan').defaultTo(1.577e10) // 6 months
})
await knex.schema.createTable('user_server_app_tokens', (table) => {
table
.string('appId')
.references('id')
.inTable('server_apps')
.notNullable()
.onDelete('cascade')
.index()
table
.string('userId')
.references('id')
.inTable('users')
.notNullable()
.onDelete('cascade')
.index()
table
.string('tokenId')
.references('id')
.inTable('api_tokens')
.notNullable()
.onDelete('cascade')
.index()
})
// let appTokenScopes = [ {
// name: 'apps:read',
// description: 'See what applications you have created or have authorized.'
// }, {
// name: 'apps:write',
// description: 'Register applications on your behalf.'
// } ]
// await knex( 'scopes' ).insert( appTokenScopes )
}
const down = async (knex) => {
await knex.schema.dropTableIfExists('server_apps_scopes')
await knex.schema.dropTableIfExists('authorization_codes')
await knex.schema.dropTableIfExists('refresh_tokens')
await knex.schema.dropTableIfExists('user_server_app_tokens')
await knex.schema.dropTableIfExists('server_apps')
}
export { up, down }