Skip to content

Commit

Permalink
Fixes issues with migration scripts not working for 0.6.5 and 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KSJaay committed Dec 23, 2024
1 parent 57d7442 commit f21fe3b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
8 changes: 8 additions & 0 deletions docs/internals/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Previous updates

## 0.7.1

### Fixes issues with migration scripts not working for 0.6.5 and 0.7.0

### Summary

While migrating from 0.6.0 to 0.7.0, I noticed that the migration scripts weren't working for both of 0.6.5 and 0.7.0. This update fixes the scripts so they work for both versions. Will be running more tests on migration scripts in the future to make sure this doesn't happen again.

## 0.7.0

### Adds support for PostgreSQL and new setup system
Expand Down
2 changes: 1 addition & 1 deletion scripts/migrations/cache-0-6-5.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const migrate = async () => {
const client = await SQLite.connect();

await client.schema.alterTable('certificate', (table) => {
table.timestamp('nextCheck').defaultTo(client.fn.now());
table.timestamp('nextCheck');
});

logger.info('Migrations', { message: '0.6.5 has been applied' });
Expand Down
4 changes: 1 addition & 3 deletions scripts/migrations/postgres-0-7-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ const migrate = async () => {
logger.info('Heartbeats - Converting createdAt to datetime...');
await client.schema.alterTable('heartbeat', (table) => {
table.datetime('date');
table.index(['monitorId', 'date']);
});

logger.info('Heartbeats - Updating createdAt...');
for (const heartbeat of heartbeats) {
const date = new Date(heartbeat.date).toISOString();
await SQLite.client('heartbeat')
.where({ monitorId: heartbeat.monitorId })
.where({ id: heartbeat.id })
.update({ date });
}

Expand All @@ -92,7 +91,6 @@ const migrate = async () => {
logger.info('Hourly Heartbeats - Converting date to datetime...');
await client.schema.alterTable('hourly_heartbeat', (table) => {
table.datetime('date');
table.index(['monitorId', 'date']);
});

logger.info('Hourly Heartbeats - Updating date...');
Expand Down
6 changes: 3 additions & 3 deletions server/database/sqlite/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class SQLite {
table.string('avatar');
table.boolean('isVerified').defaultTo(0);
table.integer('permission').defaultTo(4);
table.datetime('createdAt').defaultTo(this.client.fn.now());
table.datetime('createdAt');

table.index('email');
table.index('isVerified');
Expand Down Expand Up @@ -138,7 +138,7 @@ export class SQLite {
table.text('content').defaultTo(null);
table.string('friendlyName');
table.text('data');
table.datetime('createdAt').defaultTo(this.client.fn.now());
table.datetime('createdAt');

table.index('id');
});
Expand Down Expand Up @@ -211,7 +211,7 @@ export class SQLite {
table.datetime('validTill');
table.text('validOn');
table.integer('daysRemaining').defaultTo(0);
table.datetime('nextCheck').defaultTo(this.client.fn.now());
table.datetime('nextCheck');

table.index('monitorId');
});
Expand Down

0 comments on commit f21fe3b

Please sign in to comment.