Skip to content

Commit

Permalink
better table naming, delete handling, dev data
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbo committed Aug 30, 2023
1 parent 77be825 commit 5e47633
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
4 changes: 3 additions & 1 deletion api/models/build-task-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const associate = ({
}) => {
// Associations
BuildTaskType.hasMany(BuildTask, {
foreignKey: 'build_task_type',
foreignKey: 'buildTaskTypeId',
});
};

Expand All @@ -23,6 +23,8 @@ module.exports = (sequelize, DataTypes) => {
metadata: {
type: DataTypes.JSON,
},
}, {
tableName: 'build_task_type',
}
);

Expand Down
10 changes: 10 additions & 0 deletions api/models/build-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ module.exports = (sequelize, DataTypes) => {
isIn: [Statuses.values],
},
},
}, {
tableName: 'build_task',
paranoid: true,
indexes: [
{
name: 'build_task_build_id_type_index',
unique: true,
fields: ['buildId'],
},
],
}
);

Expand Down
2 changes: 1 addition & 1 deletion api/models/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const associate = ({
allowNull: false,
});
Build.hasMany(BuildTask, {
foreignKey: 'build_task',
foreignKey: 'buildId',
});

// Scopes
Expand Down
9 changes: 7 additions & 2 deletions migrations/20230829172947-build-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const TYPE_TABLE_SCHEMA = {
name: { type: "string", notNull: true },
description: { type: "string", notNull: true },
metadata: { type: "jsonb", allowNull: true },
createdAt: { type: "timestamp", notNull: true },
updatedAt: { type: "timestamp", notNull: true },
};

const TABLE_NAME = "build_task";
Expand All @@ -18,7 +20,7 @@ const TABLE_SCHEMA = {
name: "build_task_build_id_fk",
table: "build",
rules: {
onDelete: "RESTRICT",
onDelete: "CASCADE",
onUpdate: "RESTRICT"
},
mapping: "id"
Expand All @@ -31,7 +33,7 @@ const TABLE_SCHEMA = {
name: "build_task_build_task_type_id_fk",
table: "build_task_type",
rules: {
onDelete: "RESTRICT",
onDelete: "CASCADE",
onUpdate: "RESTRICT"
},
mapping: "id"
Expand All @@ -40,6 +42,9 @@ const TABLE_SCHEMA = {
name: { type: "string", notNull: true },
status: { type: "string", notNull: true, default: "created" },
artifact: { type: "string", allowNull: true },
createdAt: { type: "timestamp", notNull: true },
updatedAt: { type: "timestamp", notNull: true },
deletedAt: { type: "timestamp", allowNull: true },
};

exports.up = async (db) => {
Expand Down
16 changes: 16 additions & 0 deletions scripts/create-dev-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const cleanDatabase = require('../api/utils/cleanDatabase');
const {
ActionType,
Build,
BuildTaskType,
BuildTask,
BuildLog,
Domain,
Event,
Expand Down Expand Up @@ -434,6 +436,20 @@ async function createData() {
})),
]);

const taskType = await BuildTaskType.create({
name: 'test',
description: 'test',
metadata: {
foo: 'bar',
},
});
await BuildTask.create({
buildId: nodeSiteBuilds[0].id,
buildTaskTypeId: taskType.id,
name: 'type',
status: 'processing',
});

const goSiteBuilds = await Promise.all([
Build.create({
branch: goSite.defaultBranch,
Expand Down

0 comments on commit 5e47633

Please sign in to comment.