From e91fd260b400bab2e3c8182a2e0666022c93ca0e Mon Sep 17 00:00:00 2001 From: nirapx <51790021+nirapx@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:21:44 +0300 Subject: [PATCH] rename --- seed/postgres/component.go | 12 ++++++------ seed/postgres/config.go | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/seed/postgres/component.go b/seed/postgres/component.go index b0acac9..a432d7b 100644 --- a/seed/postgres/component.go +++ b/seed/postgres/component.go @@ -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 @@ -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), )) } } diff --git a/seed/postgres/config.go b/seed/postgres/config.go index 12efd46..d4c8f61 100644 --- a/seed/postgres/config.go +++ b/seed/postgres/config.go @@ -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"` }