Skip to content

Commit

Permalink
chore: fix more timestamps fields, stored enum for source_type for de…
Browse files Browse the repository at this point in the history
…ployment and task
  • Loading branch information
shreddedbacon committed Oct 29, 2024
1 parent 961286f commit 305e944
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 8 deletions.
1 change: 0 additions & 1 deletion docker-compose.local-dev-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ volumes:
services:
api-db:
image: uselagoon/mysql-8.0:latest
command: mysqld --sql_mode=""
environment:
- MYSQL_USER=api
- MYSQL_PASSWORD=api
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports.up = function(knex) {
// fix the way the enum values are stored to be lowercase for mysql strict
return Promise.all([
knex('deployment')
.where('source_type', '=', 'API')
.update('source_type', 'api'),
knex('deployment')
.where('source_type', '=', 'WEBHOOK')
.update('source_type', 'webhook'),
knex('task')
.where('source_type', '=', 'API')
.update('source_type', 'api'),
]);
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function(knex) {
return knex.schema;
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ exports.up = async function(knex) {
table.specificType('description', 'text').notNullable().alter();
table.string('group_name', 300).alter();
table.specificType('command', 'text').alter();
table.timestamp('deleted').notNullable().alter();
table.timestamp('deleted').alter();
})
.alterTable('deployment', function (table) {
table.timestamp('created').notNullable().defaultTo(knex.fn.now()).alter();
table.timestamp('started').alter();
table.timestamp('completed').alter();
})
.alterTable('environment', function (table) {
table.timestamp('deleted').notNullable().alter();
table.timestamp('deleted').alter();
})
.alterTable('environment_fact', function (table) {
table.specificType('description', 'text').alter();
Expand All @@ -22,17 +27,22 @@ exports.up = async function(knex) {
table.string('lagoon_service', 100).defaultTo('').alter();
table.specificType('description', 'text').alter();
table.string('version', 100).defaultTo('').alter();
table.timestamp('deleted').notNullable().alter();
table.timestamp('deleted').alter();
})
.alterTable('organization', function (table) {
table.specificType('description', 'text').notNullable().alter();
})
.alterTable('s3_file', function (table) {
table.timestamp('created').notNullable().defaultTo(knex.fn.now()).alter();
table.timestamp('deleted').notNullable().alter();
table.timestamp('deleted').alter();
})
.alterTable('task', function (table) {
table.timestamp('created').notNullable().defaultTo(knex.fn.now()).alter();
table.timestamp('started').alter();
table.timestamp('completed').alter();
})
.alterTable('workflow', function (table) {
table.timestamp('deleted').notNullable().alter();
table.timestamp('deleted').alter();
})
};

Expand All @@ -50,6 +60,11 @@ exports.down = async function(knex) {
table.string('group_name', 300).alter();
table.specificType('command', 'text').defaultTo('').alter();
})
.alterTable('deployment', function (table) {
table.datetime('created').notNullable().defaultTo(knex.fn.now()).alter();
table.datetime('started').alter();
table.datetime('completed').alter();
})
.alterTable('environment_fact', function (table) {
table.specificType('description', 'text').defaultTo('').alter();
table.specificType('category', 'text').defaultTo('').alter();
Expand All @@ -67,6 +82,11 @@ exports.down = async function(knex) {
table.datetime('created').notNullable().defaultTo(knex.fn.now()).alter();
table.datetime('deleted').notNullable().alter();
})
.alterTable('task', function (table) {
table.datetime('created').notNullable().defaultTo(knex.fn.now()).alter();
table.datetime('started').alter();
table.datetime('completed').alter();
})
.alterTable('organization', function (table) {
table.specificType('description', 'text').notNullable().defaultTo('').alter();
})
Expand Down
2 changes: 1 addition & 1 deletion services/api/src/models/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Environment {
openshiftProjectName?: string; // varchar(100) COLLATE utf8_bin DEFAULT NULL,
updated?: string; // timestamp NOT NULL DEFAULT current_timestamp(),
created?: string; // timestamp NOT NULL DEFAULT current_timestamp(),
deleted?: string; // timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
deleted?: string;
route?: string; // varchar(300) COLLATE utf8_bin DEFAULT NULL,
routes?: string; // text COLLATE utf8_bin DEFAULT NULL,
autoIdle?: Boolean; // int(1) NOT NULL DEFAULT 1,
Expand Down
3 changes: 3 additions & 0 deletions services/api/src/resources/deployment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ export const addDeployment: ResolverFn = async (
if (!sourceType) {
sourceType = "API"
}
if (sourceType) {
sourceType.toLocaleLowerCase();
}
const { insertId } = await query(
sqlClientPool,
Sql.insertDeployment({
Expand Down
1 change: 0 additions & 1 deletion services/api/src/resources/environment/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export const addOrUpdateEnvironment: ResolverFn = async (
const inputDefaults = {
deployHeadRef: null,
deployTitle: null,
deleted: 0,
};

const insertData = R.pick([
Expand Down
3 changes: 3 additions & 0 deletions services/api/src/resources/task/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export const Helpers = (sqlClientPool: Pool, hasPermission, adminScopes) => {
sourceUser: string;
sourceType: string;
}) => {
if (sourceType) {
sourceType.toLocaleLowerCase();
}
const { insertId } = await query(
sqlClientPool,
Sql.insertTask({
Expand Down

0 comments on commit 305e944

Please sign in to comment.