Skip to content

Commit

Permalink
refactor(migrate): read env from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
tfkhdyt committed Sep 27, 2023
1 parent 6eac208 commit 7f322ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
21 changes: 9 additions & 12 deletions src/Bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,23 @@ export default class App {
const ejaan = `*${result.data!.ejaan.join(' ').toLowerCase()}*`
const pengertian = result.data!.pengertian.map((value, index) => {
// console.log(value)
return `${index + 1}. ${
value.jenisKata.length !== 0
return `${index + 1}. ${value.jenisKata.length !== 0
? '_' + value.jenisKata.join(', ') + '_\n'
: ''
}\`${value.deskripsi}\``
}\`${value.deskripsi}\``
})

this.sendMessage(
ctx,
`${ejaan} ${
result.data!.kataTidakBaku ? '\n' + result.data!.kataTidakBaku : ''
`${ejaan} ${result.data!.kataTidakBaku ? '\n' + result.data!.kataTidakBaku : ''
}
${pengertian.join('\n\n')}${
result.data!.prakategorial
? `_Prakategorial:_ ${result
.data!.prakategorial.split(', ')
.map((text) => `\`${text}\``)
.join(', ')}`
: ''
${pengertian.join('\n\n')}${result.data!.prakategorial
? `. _Prakategorial:_ ${result
.data!.prakategorial.split(', ')
.map((text) => `\`${text}\``)
.join(', ')}`
: ''
}
`,
// this.createInlineKeyboard(
Expand Down
21 changes: 15 additions & 6 deletions src/db/postgres/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { createClient } from '@libsql/client/.'
import { createClient } from '@libsql/client'
import { drizzle } from 'drizzle-orm/libsql'
import { migrate } from 'drizzle-orm/libsql/migrator'

import config from '../../config/config'

console.log('Running migration...')

const client = createClient({
url: config.databaseUrl,
authToken: config.databaseAuthToken,
})
const db = drizzle(client)
await migrate(db, { migrationsFolder: './drizzle' })

console.log('Migrations is done')
async function main() {
try {
await migrate(db, {
migrationsFolder: 'drizzle',
})
console.log('Tables migrated!')
process.exit(0)
} catch (error) {
console.error('Error performing migration: ', error)
process.exit(1)
}
}

main()

0 comments on commit 7f322ea

Please sign in to comment.