Skip to content

Commit

Permalink
✨ add column githubUsername to users table
Browse files Browse the repository at this point in the history
  • Loading branch information
Marigold committed Nov 11, 2024
1 parent 358e068 commit 3133ff6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
20 changes: 14 additions & 6 deletions adminSiteServer/authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,22 @@ export async function tailscaleAuthMiddleware(
return next()
}

const user = await db
.knexInstance()
.table("users")
.where({ fullName: githubUserName })
.first()
let user
try {
// Look up user by 'githubUsername'
user = await db
.knexInstance()
.table("users")
.where({ githubUsername: githubUserName })
.first()
} catch (error) {
console.error(`Error looking up user by githubUsername: ${error}`)
return next()
}

if (!user) {
console.error(
`User with name ${githubUserName} not found in MySQL. Please change your Github profile name to match your MySQL user.`
`User with githubUsername ${githubUserName} not found in MySQL.`
)
return next()
}
Expand Down
39 changes: 39 additions & 0 deletions db/migration/1731317168994-AddGithubUsernameToUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from "typeorm"

export class AddGithubUsernameToUsers1731317168994
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
// Add 'githubUsername' column using raw SQL
await queryRunner.query(`
ALTER TABLE users ADD COLUMN githubUsername VARCHAR(255) NULL;
`)

// Set 'githubUsername' = 'fullName' by default
await queryRunner.query(`
UPDATE users
SET githubUsername = fullName;
`)

// Update 'githubUsername' for specific users
await queryRunner.query(`
UPDATE users
SET githubUsername = 'Tuna' WHERE fullName = 'Tuna Acisu';
UPDATE users
SET githubUsername = 'bastianherre' WHERE fullName = 'Bastian Herre';
UPDATE users
SET githubUsername = 'JoeHasell' WHERE fullName = 'Joe Hasell';
UPDATE users
SET githubUsername = 'mrwbkrm' WHERE fullName = 'Marwa Boukarim';
UPDATE users
SET githubUsername = 'veronikasamborska1994' WHERE fullName = 'Veronika Samborska';
`)
}

public async down(queryRunner: QueryRunner): Promise<void> {
// Remove 'githubUsername' column using raw SQL
await queryRunner.query(`
ALTER TABLE users DROP COLUMN githubUsername;
`)
}
}

0 comments on commit 3133ff6

Please sign in to comment.