D knexfile.js => knexfile.js +0 -40
@@ 1,40 0,0 @@
-// Update with your config settings.
-
-/**
- * @type { Object.<string, import("knex").Knex.Config> }
- */
-module.exports = {
-
- staging: {
- client: 'postgresql',
- connection: {
- database: 'my_db',
- user: 'username',
- password: 'password'
- },
- pool: {
- min: 2,
- max: 10
- },
- migrations: {
- tableName: 'knex_migrations'
- }
- },
-
- production: {
- client: 'postgresql',
- connection: {
- database: 'my_db',
- user: 'username',
- password: 'password'
- },
- pool: {
- min: 2,
- max: 10
- },
- migrations: {
- tableName: 'knex_migrations'
- }
- }
-
-};
M migrations/20230419111959_setup_base_db.ts => migrations/20230419111959_setup_base_db.ts +7 -47
@@ 1,10 1,10 @@
import {Knex} from "knex";
-import {neosUserPerms} from "../src/types/dbTypes";
+import {SCHEMA_NAME} from "../src/environment";
export async function up(knex: Knex): Promise<void> {
- await knex.schema.createSchemaIfNotExists('neosmanager');
+ await knex.schema.createSchemaIfNotExists(SCHEMA_NAME);
- await knex.schema.withSchema('neosmanager').createTable('images', (table) => {
+ await knex.schema.withSchema(SCHEMA_NAME).createTable('images', (table) => {
table
.uuid('id')
.comment('Image ID')
@@ 14,58 14,18 @@ export async function up(knex: Knex): Promise<void> {
table
.text('image_id')
.comment('ID of the image')
- .notNullable();
+ .notNullable()
+ .unique();
table
.text('image_tag')
.comment('Tag of the image')
.notNullable();
});
-
- await knex.schema.withSchema('neosmanager').createTable('servers', (table) => {
- table
- .uuid('id')
- .primary()
- .comment('UUID of the row')
- .defaultTo(knex.raw('gen_random_uuid()'));
-
- table
- .text('server_name')
- .comment('name of server');
-
- table
- .text('comment')
- .comment('Comment on the server');
-
- table
- .text('container_id')
- .comment('Container ID of the server')
- .notNullable();
-
- table
- .foreign('image_id').references('images.id').deferrable('deferred')
- .notNullable();
- });
-
- await knex.schema.withSchema('neosmanager').createTable('neos_permissions', (table) => {
- table
- .uuid('id')
- .primary()
- .comment('UUID of the row')
- .defaultTo(knex.raw('gen_random_uuid()'));
-
- table
- .text('username')
- .comment('username of the user')
- .notNullable();
-
- table
- .enum('permissions', ['Admin', 'Builder', 'Moderator', 'Guest', 'Spectator'])
- .notNullable();
- });
}
-export async function down(knex: Knex): Promise<void> {
+export function down(): void {
+ return;
}
A migrations/20230419134314_add_servers_table.ts => migrations/20230419134314_add_servers_table.ts +34 -0
@@ 0,0 1,34 @@
+import { Knex } from "knex";
+import {SCHEMA_NAME} from "../src/environment";
+
+
+export async function up(knex: Knex): Promise<void> {
+ await knex.schema.withSchema(SCHEMA_NAME).createTable('servers', (table) => {
+ table
+ .uuid('id')
+ .primary()
+ .comment('UUID of the row')
+ .defaultTo(knex.raw('gen_random_uuid()'));
+
+ table
+ .text('server_name')
+ .comment('name of server');
+
+ table
+ .text('comment')
+ .comment('Comment on the server');
+
+ table
+ .text('container_id')
+ .comment('Container ID of the server')
+ .notNullable();
+
+ table
+ .text('image_id').references('image_id').inTable('images');
+ });
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+}
+
A migrations/20230419152153_add_perms_table.ts => migrations/20230419152153_add_perms_table.ts +27 -0
@@ 0,0 1,27 @@
+import { Knex } from "knex";
+import { SCHEMA_NAME } from "../src/environment";
+
+
+export async function up(knex: Knex): Promise<void> {
+ await knex.schema.withSchema(SCHEMA_NAME).createTable('neos_permissions', (table) => {
+ table
+ .uuid('id')
+ .primary()
+ .comment('UUID of the row')
+ .defaultTo(knex.raw('gen_random_uuid()'));
+
+ table
+ .text('username')
+ .comment('username of the user')
+ .notNullable();
+
+ table
+ .enum('permissions', ['Admin', 'Builder', 'Moderator', 'Guest', 'Spectator'])
+ .notNullable();
+ });
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+}
+