All Projects → gobuffalo → Fizz

gobuffalo / Fizz

Licence: mit
A Common DSL for Migrating Databases

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Fizz

Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+2195.65%)
Mutual labels:  mysql, sqlite, postgres, migrations
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+8282.61%)
Mutual labels:  migrations, mysql, sqlite, postgres
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 2,315 (+2416.3%)
Mutual labels:  migrations, mysql, sqlite, postgres
Wetland
A Node.js ORM, mapping-based. Works with MySQL, PostgreSQL, SQLite and more.
Stars: ✭ 261 (+183.7%)
Mutual labels:  mysql, sqlite, postgres
Dbmate
🚀 A lightweight, framework-agnostic database migration tool.
Stars: ✭ 2,228 (+2321.74%)
Mutual labels:  migrations, mysql, sqlite
East
node.js database migration tool
Stars: ✭ 53 (-42.39%)
Mutual labels:  mysql, sqlite, postgres
Sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.
Stars: ✭ 5,039 (+5377.17%)
Mutual labels:  mysql, sqlite, postgres
Requery
requery - modern SQL based query & persistence for Java / Kotlin / Android
Stars: ✭ 3,071 (+3238.04%)
Mutual labels:  mysql, sqlite, postgres
Rbatis
Rust ORM Framework High Performance Rust SQL-ORM(JSON based)
Stars: ✭ 482 (+423.91%)
Mutual labels:  mysql, sqlite, postgres
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+6926.09%)
Mutual labels:  mysql, sqlite, postgres
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+969.57%)
Mutual labels:  mysql, sqlite, postgres
Pop
A Tasty Treat For All Your Database Needs
Stars: ✭ 1,045 (+1035.87%)
Mutual labels:  migrations, mysql, sqlite
Databases
Async database support for Python. 🗄
Stars: ✭ 2,602 (+2728.26%)
Mutual labels:  mysql, sqlite, postgres
Atdatabases
TypeScript clients for databases that prevent SQL Injection
Stars: ✭ 154 (+67.39%)
Mutual labels:  mysql, sqlite, postgres
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1277.17%)
Mutual labels:  mysql, sqlite, postgres
Rdbc
Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Stars: ✭ 328 (+256.52%)
Mutual labels:  mysql, sqlite, postgres
Ugin
UGin is an API boilerplate written in Go (Golang) with Gin Framework.
Stars: ✭ 110 (+19.57%)
Mutual labels:  mysql, sqlite, postgres
Sqhell.vim
An SQL wrapper for vim
Stars: ✭ 113 (+22.83%)
Mutual labels:  mysql, sqlite, postgres
Vscode Sqltools
Database management for VSCode
Stars: ✭ 741 (+705.43%)
Mutual labels:  mysql, sqlite, postgres
Ebean
Ebean ORM
Stars: ✭ 1,172 (+1173.91%)
Mutual labels:  mysql, sqlite, postgres

Fizz

A Common DSL for Migrating Databases

Create a Table

create_table("users") {
  t.Column("id", "integer", {primary: true})
  t.Column("email", "string", {})
  t.Column("twitter_handle", "string", {"size": 50})
  t.Column("age", "integer", {"default": 0})
  t.Column("admin", "bool", {"default": false})
  t.Column("company_id", "uuid", {"default_raw": "uuid_generate_v1()"})
  t.Column("bio", "text", {"null": true})
  t.Column("joined_at", "timestamp", {})
  t.Index("email", {"unique": true})
}

create_table("todos") {
  t.Column("user_id", "integer", {})
  t.Column("title", "string", {"size": 100})
  t.Column("details", "text", {"null": true})
  t.ForeignKey("user_id", {"users": ["id"]}, {"on_delete": "cascade"})
}

The id column don't have to be an integer. For instance, your can use an UUID type instead:

create_table("users") {
  t.Column("id", "uuid", {primary: true})
  // ...
}

By default, fizz will generate two timestamp columns: created_at and updated_at.

The t.Columns method takes the following arguments: name of the column, the type of the field, and finally the last argument is any options you want to set on that column.

"Common" Types:

  • string
  • text
  • timestamp, time, datetime
  • integer
  • bool
  • uuid

Any other type passed it will be be passed straight through to the underlying database.

For example for PostgreSQL you could pass jsonband 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 a varchar(50) in Postgres you would do: t.Column("column_name", "string", {"size": 50})
  • null - By default columns are not allowed to be null.
  • default - The default value you want for this column. By default this is null.
  • default_raw - The default value defined as a database function.
  • after - (MySQL Only) Add a column after another column in the table. example: {"after":"created_at"}
  • first - (MySQL Only) Add a column to the first position in the table. example: {"first": true}

Composite primary key

create_table("user_privileges") {
	t.Column("user_id", "int")
	t.Column("privilege_id", "int")
	t.PrimaryKey("user_id", "privilege_id")
}

Please note that the t.PrimaryKey statement MUST be after the columns definitions.

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.

Alter a column

change_column("table_name", "column_name", "string", {})

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 to table_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")

Add a Foreign Key

add_foreign_key("table_name", "field", {"ref_table_name": ["ref_column"]}, {
    "name": "optional_fk_name",
    "on_delete": "action",
    "on_update": "action",
})

Supported Options

  • name - This defaults to table_name_ref_table_name_ref_column_name_fk
  • on_delete - CASCADE, SET NULL, ...
  • on_update

Note: on_update and on_delete are not supported on CockroachDB yet.

Drop a Foreign Key

drop_foreign_key("table_name", "fk_name", {"if_exists": true})

Supported Options

  • if_exists - Adds IF EXISTS condition

Raw SQL

sql("select * from users;")

Execute an External Command

Sometimes during a migration you need to shell out to an external command.

exec("echo hello")

Development

Testing

To run end-to-end tests, use

make test

If you made changes to the end-to-end tests and want to update the fixtures, run the following command a couple of times until tests pass:

REFRESH_FIXTURES=true make test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].