Skip to content
Permalink
Browse files

Also make defaults for primary keys

  • Loading branch information...
shosti committed Mar 6, 2018
1 parent 2e4967a commit 133c4e64ef20e8efd08b4fbff752c43a58f510ef
Showing with 11 additions and 10 deletions.
  1. +8 −0 action/column.go
  2. +1 −9 action/createcolumn.go
  3. +2 −1 action/createtable.go
@@ -19,3 +19,11 @@ func (c *Column) GetTypeSchemaStr(schema string) string {

return ""
}

func (c *Column) DefaultStatement() string {
if c.Default == "" {
return ""
}

return " DEFAULT " + c.Default
}
@@ -25,7 +25,7 @@ func (a *CreateColumn) Execute(c *Context) error {
a.Column.Name,
a.Column.GetTypeSchemaStr(a.SchemaName),
a.Column.Type,
a.defaultStatement(),
a.Column.DefaultStatement(),
a.notNullStatement(),
),
)
@@ -41,14 +41,6 @@ func (a *CreateColumn) notNullStatement() string {
return ""
}

func (a *CreateColumn) defaultStatement() string {
if a.Column.Default == "" {
return ""
}

return " DEFAULT " + a.Column.Default
}

func (a *CreateColumn) Filter(targetExpression string) bool {
return true
}
@@ -20,12 +20,13 @@ func init() {
func (a *CreateTable) Execute(c *Context) error {
_, err := c.Tx.Exec(
fmt.Sprintf(
"CREATE TABLE \"%s\".\"%s\" (\"%s\" %s\"%s\" PRIMARY KEY);",
"CREATE TABLE \"%s\".\"%s\" (\"%s\" %s\"%s\"%s PRIMARY KEY);",
a.SchemaName,
a.TableName,
a.PrimaryKey.Name,
a.PrimaryKey.GetTypeSchemaStr(a.SchemaName),
a.PrimaryKey.Type,
a.PrimaryKey.DefaultStatement(),
),
)

0 comments on commit 133c4e6

Please sign in to comment.
You can’t perform that action at this time.