README ¶
Fizz
A Common DSL for Migrating Databases
Create a Table
create_table("users", func(t) {
t.Column("email", "string", {})
t.Column("twitter_handle", "string", {"size": 50})
t.Column("age", "integer", {"default": 0})
t.Column("admin", "boolean", {"default": false})
t.Column("bio", "text", {"null": true})
t.Column("joined_at", "timestamp", {})
})
The create_table
function will also generate an id
column of type integer
that will auto-increment. It will also generate two timestamp
columns; created_at
and updated_at
.
Columns all have the same syntax. First is the name of the column. Second is the type of the field. Third is any options you want to set on that column.
"Common" Types:
string
text
timestamp
integer
boolean
Any other type passed it will be be passed straight through to the underlying database. For example for PostgreSQL you could pass jsonb
and it will be supported, however, SQLite will yell very loudly at you if you do the same thing!
Supported Options:
size
- The size of the column. For example if you wanted avarchar(50)
in Postgres you would do:t.Column("column_name", "string", {"size": 50})
null
- By default columns are not allowed to benull
.default
- The default value you want for this column. By default this isnull
.
Drop a Table
drop_table("table_name")
Rename a Table
rename_table("old_table_name", "new_table_name")
Add a Column
add_column("table_name", "column_name", "string", {})
See above for more details on column types and options.
Rename a Column
rename_column("table_name", "old_column_name", "new_column_name")
Drop a Column
drop_column("table_name", "column_name")
Add an Index
Supported Options:
name
- This defaults totable_name_column_name_idx
unique
Simple Index:
add_index("table_name", "column_name", {})
Multi-Column Index:
add_index("table_name", ["column_1", "column_2"], {})
Unique Index:
add_index("table_name", "column_name", {"unique": true})
Index Names:
add_index("table_name", "column_name", {}) # name => table_name_column_name_idx
add_index("table_name", "column_name", {"name": "custom_index_name"})
Rename an Index
rename_index("table_name", "old_index_name", "new_index_name")
Drop an Index
drop_index("table_name", "index_name")
Raw SQL
raw("select * from users;")
All calls to raw
must end with a ;
!
Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CREATED_COL = Column{Name: "created_at", ColType: "timestamp", Options: Options{}}
View Source
var ID_COL = Column{ Name: "id", Primary: true, ColType: "integer", Options: Options{}, }
View Source
var UPDATED_COL = Column{Name: "updated_at", ColType: "timestamp", Options: Options{}}
Functions ¶
Types ¶
type BubbleType ¶
type BubbleType int
type Bubbler ¶
type Bubbler struct { Translator // contains filtered or unexported fields }
func NewBubbler ¶
func NewBubbler(t Translator) *Bubbler
type Translator ¶
type Translator interface { CreateTable(Table) (string, error) DropTable(Table) (string, error) RenameTable([]Table) (string, error) AddColumn(Table) (string, error) DropColumn(Table) (string, error) RenameColumn(Table) (string, error) AddIndex(Table) (string, error) DropIndex(Table) (string, error) RenameIndex(Table) (string, error) }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.