feat: seed company record from BUSINESS_NAME env var on first startup
All checks were successful
Build & Release / build (push) Successful in 19s
All checks were successful
Build & Release / build (push) Successful in 19s
This commit is contained in:
@@ -38,6 +38,7 @@ import { ModuleService } from './services/module.service.js'
|
||||
import { AppConfigService } from './services/config.service.js'
|
||||
import { SettingsService } from './services/settings.service.js'
|
||||
import { users } from './db/schema/users.js'
|
||||
import { companies } from './db/schema/stores.js'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
async function seedInitialUser(app: Awaited<ReturnType<typeof buildApp>>) {
|
||||
@@ -73,6 +74,17 @@ async function seedEmailSettings(app: Awaited<ReturnType<typeof buildApp>>) {
|
||||
app.log.info('Email settings seeded from environment')
|
||||
}
|
||||
|
||||
async function seedCompany(app: Awaited<ReturnType<typeof buildApp>>) {
|
||||
const name = process.env.BUSINESS_NAME
|
||||
if (!name) return
|
||||
|
||||
const existing = await app.db.select({ id: companies.id }).from(companies).limit(1)
|
||||
if (existing.length > 0) return
|
||||
|
||||
await app.db.insert(companies).values({ name })
|
||||
app.log.info({ name }, 'Company seeded from environment')
|
||||
}
|
||||
|
||||
export async function buildApp() {
|
||||
const app = Fastify({
|
||||
logger: {
|
||||
@@ -209,6 +221,11 @@ export async function buildApp() {
|
||||
} catch (err) {
|
||||
app.log.error({ err }, 'Failed to seed email settings')
|
||||
}
|
||||
try {
|
||||
await seedCompany(app)
|
||||
} catch (err) {
|
||||
app.log.error({ err }, 'Failed to seed company')
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user