-
Notifications
You must be signed in to change notification settings - Fork 3
Seeder and Emulator Setup #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
9a170ec
3ddbf6e
2e9b667
f8e0b07
6cde37d
314708b
0900dd5
9cb29bf
2b85cee
b09876f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* eslint-disable */ | ||
| require("dotenv").config(); | ||
|
|
||
| module.exports = { | ||
| development: { | ||
| username: process.env.POSTGRES_USER || "postgres", | ||
| password: process.env.POSTGRES_PASSWORD || "password", | ||
| database: process.env.POSTGRES_DB_NAME || "humane_society_dev", | ||
| host: process.env.DB_HOST || "db", | ||
| port: process.env.DB_PORT || 5432, | ||
| dialect: "postgres", | ||
| logging: false, | ||
| }, | ||
| test: { | ||
| username: process.env.POSTGRES_USER || "postgres", | ||
| password: process.env.POSTGRES_PASSWORD || "password", | ||
| database: process.env.POSTGRES_DB_TEST || "humane_society_test", | ||
| host: process.env.DB_HOST || "db", | ||
| port: process.env.DB_PORT || 5432, | ||
| dialect: "postgres", | ||
| logging: false, | ||
| }, | ||
| production: { | ||
| use_env_variable: "DATABASE_URL", | ||
| dialect: "postgres", | ||
| logging: false, | ||
| }, | ||
| }; |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Document code blocks for clarity |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* eslint-disable */ | ||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import admin from "firebase-admin"; | ||
| import "dotenv/config"; | ||
|
|
||
| if (!process.env.FIREBASE_AUTH_EMULATOR_HOST) { | ||
| console.error( | ||
| "Set FIREBASE_AUTH_EMULATOR_HOST (e.g., host.docker.internal:9099).", | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!admin.apps.length) { | ||
| admin.initializeApp({ | ||
| projectId: process.env.FIREBASE_PROJECT_ID || "uw-blueprint-starter-code", | ||
| }); | ||
| } | ||
|
|
||
| const auth = admin.auth(); | ||
|
|
||
| const USERS = [ | ||
|
||
| { | ||
| label: "admin_001", | ||
| email: "john.smith@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "John Smith", | ||
| }, | ||
| { | ||
| label: "admin_002", | ||
| email: "sarah.johnson@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Sarah Johnson", | ||
| }, | ||
| { | ||
| label: "behaviourist_001", | ||
| email: "emily.wilson@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Emily Wilson", | ||
| }, | ||
| { | ||
| label: "behaviourist_002", | ||
| email: "michael.brown@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Michael Brown", | ||
| }, | ||
| { | ||
| label: "staff_001", | ||
| email: "lisa.davis@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Lisa Davis", | ||
| }, | ||
| { | ||
| label: "staff_002", | ||
| email: "robert.miller@humanesociety.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Robert Miller", | ||
| }, | ||
| { | ||
| label: "volunteer_001", | ||
| email: "amanda.garcia@volunteer.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Amanda Garcia", | ||
| }, | ||
| { | ||
| label: "volunteer_002", | ||
| email: "kevin.martinez@volunteer.com", | ||
| password: "Passw0rd!", | ||
| displayName: "Kevin Martinez", | ||
| }, | ||
| ]; | ||
|
|
||
| (async () => { | ||
| const map: Record<string, string> = {}; | ||
| for (const u of USERS) { | ||
| try { | ||
| const ex = await auth.getUserByEmail(u.email); | ||
| map[u.label] = ex.uid; | ||
| } catch { | ||
| const created = await auth.createUser({ | ||
| email: u.email, | ||
| password: u.password, | ||
| displayName: u.displayName, | ||
| emailVerified: true, | ||
| }); | ||
| map[u.label] = created.uid; | ||
| } | ||
| } | ||
| const outPath = path.resolve(__dirname, "../seeders/seed-auth-map.json"); | ||
| fs.writeFileSync(outPath, JSON.stringify(map, null, 2)); | ||
| console.log("Wrote UID map:", outPath, map); | ||
| process.exit(0); | ||
| })(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* eslint-disable */ | ||
| import type { QueryInterface } from "sequelize"; | ||
| import { resolveTable, tsKeys, withTS, Rec } from "../utilities/_utils"; | ||
|
|
||
| // Pull real UIDs created by `yarn seed:auth` | ||
| let uidMap: Record<string, string>; | ||
| try { | ||
| uidMap = require("./seed-auth-map.json"); | ||
| } catch { | ||
| throw new Error( | ||
| "seed-auth-map.json not found. Run `docker compose exec ts-backend yarn seed:auth` first.", | ||
| ); | ||
| } | ||
|
|
||
| module.exports = { | ||
| up: async (queryInterface: QueryInterface) => { | ||
| const Users = await resolveTable(queryInterface, ["Users", "users"]); | ||
| const uTS = await tsKeys(queryInterface, Users); | ||
|
|
||
| const users: Rec[] = [ | ||
| { | ||
| first_name: "John", | ||
| last_name: "Smith", | ||
| auth_id: uidMap.admin_001, | ||
| role: "Administrator", | ||
| email: "john.smith@humanesociety.com", | ||
| color_level: 5, | ||
| animal_tags: "{Dog,Cat}", | ||
| status: "Active", | ||
| can_see_all_logs: true, | ||
| can_assign_users_to_tasks: true, | ||
| phone_number: "+1-555-0101", | ||
| }, | ||
| { | ||
| first_name: "Sarah", | ||
| last_name: "Johnson", | ||
| auth_id: uidMap.admin_002, | ||
| role: "Administrator", | ||
| email: "sarah.johnson@humanesociety.com", | ||
| color_level: 5, | ||
| animal_tags: "{Bird,Small Animal}", | ||
| status: "Active", | ||
| can_see_all_logs: true, | ||
| can_assign_users_to_tasks: true, | ||
| phone_number: "+1-555-0102", | ||
| }, | ||
| { | ||
| first_name: "Emily", | ||
| last_name: "Wilson", | ||
| auth_id: uidMap.behaviourist_001, | ||
| role: "Animal Behaviourist", | ||
| email: "emily.wilson@humanesociety.com", | ||
| color_level: 5, | ||
| animal_tags: "{Dog,Cat,Small Animal}", | ||
| status: "Active", | ||
| can_see_all_logs: true, | ||
| can_assign_users_to_tasks: false, | ||
| phone_number: "+1-555-0201", | ||
| }, | ||
| { | ||
| first_name: "Michael", | ||
| last_name: "Brown", | ||
| auth_id: uidMap.behaviourist_002, | ||
| role: "Animal Behaviourist", | ||
| email: "michael.brown@humanesociety.com", | ||
| color_level: 4, | ||
| animal_tags: "{Bird,Bunny}", | ||
| status: "Active", | ||
| can_see_all_logs: true, | ||
| can_assign_users_to_tasks: false, | ||
| phone_number: "+1-555-0202", | ||
| }, | ||
| { | ||
| first_name: "Lisa", | ||
| last_name: "Davis", | ||
| auth_id: uidMap.staff_001, | ||
| role: "Staff", | ||
| email: "lisa.davis@humanesociety.com", | ||
| color_level: 4, | ||
| animal_tags: "{Dog,Cat}", | ||
| status: "Active", | ||
| can_see_all_logs: false, | ||
| can_assign_users_to_tasks: true, | ||
| phone_number: "+1-555-0301", | ||
| }, | ||
| { | ||
| first_name: "Robert", | ||
| last_name: "Miller", | ||
| auth_id: uidMap.staff_002, | ||
| role: "Staff", | ||
| email: "robert.miller@humanesociety.com", | ||
| color_level: 3, | ||
| animal_tags: "{Bunny,Small Animal}", | ||
| status: "Active", | ||
| can_see_all_logs: false, | ||
| can_assign_users_to_tasks: true, | ||
| phone_number: "+1-555-0302", | ||
| }, | ||
| { | ||
| first_name: "Amanda", | ||
| last_name: "Garcia", | ||
| auth_id: uidMap.volunteer_001, | ||
| role: "Volunteer", | ||
| email: "amanda.garcia@volunteer.com", | ||
| color_level: 2, | ||
| animal_tags: "{Dog}", | ||
| status: "Active", | ||
| can_see_all_logs: false, | ||
| can_assign_users_to_tasks: false, | ||
| phone_number: "+1-555-0401", | ||
| }, | ||
| { | ||
| first_name: "Kevin", | ||
| last_name: "Martinez", | ||
| auth_id: uidMap.volunteer_002, | ||
| role: "Volunteer", | ||
| email: "kevin.martinez@volunteer.com", | ||
| color_level: 1, | ||
| animal_tags: "{Cat,Bird}", | ||
| status: "Active", | ||
| can_see_all_logs: false, | ||
| can_assign_users_to_tasks: false, | ||
| phone_number: "+1-555-0402", | ||
| }, | ||
| ].map((r) => withTS(r, uTS.createdKey, uTS.updatedKey)); | ||
|
|
||
| await queryInterface.bulkInsert(Users, users); | ||
| }, | ||
|
|
||
| down: async (queryInterface: QueryInterface) => { | ||
| const Users = await resolveTable(queryInterface, ["Users", "users"]); | ||
| await queryInterface.bulkDelete(Users, { | ||
| auth_id: [ | ||
| uidMap.admin_001, | ||
| uidMap.admin_002, | ||
| uidMap.behaviourist_001, | ||
| uidMap.behaviourist_002, | ||
| uidMap.staff_001, | ||
| uidMap.staff_002, | ||
| uidMap.volunteer_001, | ||
| uidMap.volunteer_002, | ||
| ], | ||
| } as any); | ||
| }, | ||
| }; |
Uh oh!
There was an error while loading. Please reload this page.