Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
nirapx committed Jul 16, 2024
1 parent 870c3cb commit e91fd26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions seed/postgres/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func (m *SeedComponent) Seed() error {
return err
}

for _, collection := range m.config.Data {
for _, table := range m.config.Data {

if _, err = client.Exec(fmt.Sprintf("DELETE FROM %s", collection.Table)); err != nil {
if _, err = client.Exec(fmt.Sprintf("DELETE FROM %s", table.TableName)); err != nil {
return err
}

for _, row := range collection.Rows {
sql, values := generateInsertSQL(collection.Table, row)
for _, row := range table.Rows {
sql, values := generateInsertSQL(table.TableName, row)
_, err := client.Exec(sql, values...)
if err != nil {
return err
Expand All @@ -92,8 +92,8 @@ func (m *SeedComponent) Seed() error {
if m.writer != nil {
m.writer.WriteString(fmt.Sprintf(
"inserted %s rows to %s",
m.writer.Color.Green(strconv.Itoa(len(collection.Rows))),
m.writer.Color.Cyan(collection.Table),
m.writer.Color.Green(strconv.Itoa(len(table.Rows))),
m.writer.Color.Cyan(table.TableName),
))
}
}
Expand Down
12 changes: 6 additions & 6 deletions seed/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type SeedConfig struct {
Setup string `json:"-"`

// Data - a list of objects, each represents a single postgres table and its data
Data []*SeedCollectionData `json:"data,omitempty"`
Data []*SeedTableData `json:"data,omitempty"`
}

// SeedCollectionData represents data for a Postgres table.
type SeedCollectionData struct {
// Table - the name of the target postgres table
Table string `json:"collection,omitempty"`
// SeedTableData represents data for a Postgres table.
type SeedTableData struct {
// TableName - the name of the target postgres table
TableName string `json:"table,omitempty"`

// Rows - a list of rows to insert using the postgres Exec function (a `column` tag is required for each field):
Rows []any `json:"documents,omitempty"`
Rows []any `json:"rows,omitempty"`
}

0 comments on commit e91fd26

Please sign in to comment.