Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/cmds/seed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { execSync } from 'node:child_process'
import { logFailure, logSuccess } from '../../logger'

const CMD = 'seed'

const tableNameFunction = (url, tableName, columns) => {
try {
execSync(
`psql ${url} -c "INSERT INTO reseed_queue (table_name, column_names, status) VALUES ('${tableName}', '${columns}','in-line');"`
)
logSuccess('Successfully reseeded')
} catch (error) {
logFailure({ error })
}
}

function addSeedCmd(program) {
program
.command(CMD)
.argument('url', 'Postgres database url to reseed')
.argument('<table name>', 'Table that is mapped to live columns')
.argument(
'[column names]',
'* for all live object columns or comma separated list of live object columns'
)
.action(tableNameFunction)
}

export default addSeedCmd
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import addTailCmd from './cmds/tail'
import addMigrateCmd from './cmds/migrate'
import addEnableCmd from './cmds/enable'
import addRunCmd from './cmds/run'
import addSeedCmd from './cmds/seed'

addAddCmd(program)
addCreateCmd(program)
Expand All @@ -41,5 +42,6 @@ addStartCmd(program)
addRunCmd(program)
addTailCmd(program)
addVersionCmd(program)
addSeedCmd(program)

program.parse()