Skip to content

Commit

Permalink
refactor(dev): 🔥 remove old session transfer logic and table
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesOberreiter committed Mar 2, 2023
1 parent f84f27b commit f101de2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
19 changes: 19 additions & 0 deletions db/migrations/20230302154502_remove_sessions.js
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.dropTableIfExists('sessions');
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.createTable('sessions', (t) => {
t.string('sid').notNullable().primary();
t.json('sess').notNullable();
t.timestamp('expired').notNullable().index();
});
};
32 changes: 0 additions & 32 deletions src/api/app.bootstrap.ts
Expand Up @@ -15,38 +15,6 @@ dbServer.start();
redisServer.start();
mailServer.setup();

// Helper function to copy session from MySQL to redis
async function _transferSession() {
const oldSession = await MySQLServer.knex('sessions').select('*');
for (const session of oldSession) {
const sessionData = JSON.parse(session.sess);
const newSession = {
cookie: {
...sessionData.cookie,
},
user: {
...sessionData.user,
last_visit: new Date(),
},
};
await RedisServer.client.set(
`btree_sess:${session.sid}`,
JSON.stringify(newSession),
'EX',
sessionData.cookie.originalMaxAge
);
await RedisServer.client.set(
session.sid,
JSON.stringify(newSession),
'EX',
sessionData.cookie.originalMaxAge
);
}
console.log(`Copied old session: ${oldSession.length}`);
}

// transferSession();

const application = new Application();
const httpServer = new HTTPServer(application.app);
httpServer.start();
Expand Down

0 comments on commit f101de2

Please sign in to comment.