From 8dffd7009dd1176b105184cb78532dcc5343c9a6 Mon Sep 17 00:00:00 2001 From: Hans Song Date: Sun, 12 Nov 2023 14:06:43 +1000 Subject: [PATCH] remove index name --- sqlutil/schema.go | 3 +-- sqlutil/schema_test.go | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/sqlutil/schema.go b/sqlutil/schema.go index 9576844..d65918d 100644 --- a/sqlutil/schema.go +++ b/sqlutil/schema.go @@ -54,7 +54,6 @@ func (t Table) String() string { } type Index struct { - Name string Unique bool Table string Columns Columns @@ -69,7 +68,7 @@ func (i Index) String() string { return fmt.Sprintf( "CREATE %s IF NOT EXISTS %s ON %s (%s)", indexType, - i.Name, + strings.Join(i.Columns.Names(), "_"), i.Table, strings.Join(i.Columns.Names(), ", "), ) diff --git a/sqlutil/schema_test.go b/sqlutil/schema_test.go index 9aa24ca..f88e0cc 100644 --- a/sqlutil/schema_test.go +++ b/sqlutil/schema_test.go @@ -142,17 +142,15 @@ func TestIndexString(t *testing.T) { }{ { input: sqlutil.Index{ - Name: "index", Table: "table", Columns: sqlutil.Columns{ {Name: "name"}, }, }, - expected: "CREATE INDEX IF NOT EXISTS index ON table (name)", + expected: "CREATE INDEX IF NOT EXISTS name ON table (name)", }, { input: sqlutil.Index{ - Name: "index", Table: "table", Unique: true, Columns: sqlutil.Columns{ @@ -160,7 +158,7 @@ func TestIndexString(t *testing.T) { {Name: "timestamp", Type: "INTEGER"}, }, }, - expected: "CREATE UNIQUE INDEX IF NOT EXISTS index ON table (name, timestamp)", + expected: "CREATE UNIQUE INDEX IF NOT EXISTS name_timestamp ON table (name, timestamp)", }, }