-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
99 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package krab | ||
|
||
import ( | ||
"io" | ||
"strings" | ||
) | ||
|
||
// ToSQL converts DSL struct to SQL. | ||
type ToSQL interface { | ||
ToSQL(w io.StringWriter) | ||
} | ||
|
||
// SQLStatement represents raw SQL statement. | ||
type SQLStatement string | ||
|
||
// SQLStatements represents list of raw SQL statements. | ||
type SQLStatements []SQLStatement | ||
|
||
// Append adds new SQL statement to the list from object that satisfies ToSQL interface. | ||
func (s *SQLStatements) Append(sql ToSQL) { | ||
sb := &strings.Builder{} | ||
sql.ToSQL(sb) | ||
*s = append(*s, SQLStatement(sb.String())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package krab | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/ohkrab/krab/krabdb" | ||
) | ||
|
||
// DDLDropIndex contains DSL for dropping indicies. | ||
type DDLDropIndex struct { | ||
Name string `hcl:"name,label"` | ||
|
||
Cascade bool `hcl:"cascade,optional"` | ||
Concurrently bool `hcl:"concurrently,optional"` | ||
} | ||
|
||
// ToSQL converts migration definition to SQL. | ||
func (d *DDLDropIndex) ToSQL(w io.StringWriter) { | ||
w.WriteString("DROP INDEX") | ||
if d.Concurrently { | ||
w.WriteString(" CONCURRENTLY") | ||
} | ||
w.WriteString(" ") | ||
w.WriteString(krabdb.QuoteIdentWithDots(d.Name)) | ||
if d.Cascade { | ||
w.WriteString(" CASCADE") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters