{"id":19900626,"url":"https://github.com/gobuffalo/fizz","last_synced_at":"2025-05-16T17:09:20.779Z","repository":{"id":37405560,"uuid":"137605435","full_name":"gobuffalo/fizz","owner":"gobuffalo","description":"A Common DSL for Migrating Databases","archived":false,"fork":false,"pushed_at":"2023-12-11T04:40:00.000Z","size":4963,"stargazers_count":150,"open_issues_count":18,"forks_count":34,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-12T16:48:46.053Z","etag":null,"topics":["cockroachdb","database-migrations","gobuffalo","migrations","mysql","pop","postgresql","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gobuffalo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["markbates","stanislas-m"],"patreon":"buffalo"}},"created_at":"2018-06-16T19:29:46.000Z","updated_at":"2025-02-16T12:35:32.000Z","dependencies_parsed_at":"2024-06-18T12:37:44.621Z","dependency_job_id":"4347f4e7-818a-452d-956b-e2453123eac3","html_url":"https://github.com/gobuffalo/fizz","commit_stats":null,"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Ffizz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Ffizz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Ffizz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gobuffalo%2Ffizz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gobuffalo","download_url":"https://codeload.github.com/gobuffalo/fizz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254573589,"owners_count":22093731,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cockroachdb","database-migrations","gobuffalo","migrations","mysql","pop","postgresql","sqlite"],"created_at":"2024-11-12T20:12:48.334Z","updated_at":"2025-05-16T17:09:20.757Z","avatar_url":"https://github.com/gobuffalo.png","language":"Go","readme":"# Fizz\n\n[![Actions Status](https://github.com/gobuffalo/fizz/workflows/Tests/badge.svg)](https://github.com/gobuffalo/fizz/actions)\n[![Go Reference](https://pkg.go.dev/badge/github.com/gobuffalo/fizz.svg)](https://pkg.go.dev/github.com/gobuffalo/fizz)\n\nA Common DSL for Migrating Databases\n\n\n## Supported Database Engines\n\nFizz supports minimum supported version of all supported database engines.\nCurrently, the following database engines are officially supported. (Since\nFizz is used with the migration feature of Pop, supported databases and the\nversions are correlated with Pop.)\n\n* PostgreSQL 10\n* MySQL 5.7 / MariaDB 10.3\n* SQLite3 3.22\n* CockroachDB v21.1\n* MSSQL 2017 (not fully supported)\n\n\n## Usage\n\n### Create a Table\n\n``` javascript\ncreate_table(\"users\") {\n  t.Column(\"id\", \"integer\", {primary: true})\n  t.Column(\"email\", \"string\", {})\n  t.Column(\"twitter_handle\", \"string\", {\"size\": 50})\n  t.Column(\"age\", \"integer\", {\"default\": 0})\n  t.Column(\"admin\", \"bool\", {\"default\": false})\n  t.Column(\"company_id\", \"uuid\", {\"default_raw\": \"uuid_generate_v1()\"})\n  t.Column(\"bio\", \"text\", {\"null\": true})\n  t.Column(\"joined_at\", \"timestamp\", {})\n  t.Index(\"email\", {\"unique\": true})\n}\n\ncreate_table(\"todos\") {\n  t.Column(\"user_id\", \"integer\", {})\n  t.Column(\"title\", \"string\", {\"size\": 100})\n  t.Column(\"details\", \"text\", {\"null\": true})\n  t.ForeignKey(\"user_id\", {\"users\": [\"id\"]}, {\"on_delete\": \"cascade\"})\n}\n```\n\nThe `id` column don't have to be an integer. For instance, your can use an UUID type instead:\n\n```javascript\ncreate_table(\"users\") {\n  t.Column(\"id\", \"uuid\", {primary: true})\n  // ...\n}\n```\n\nBy default, fizz will generate two `timestamp` columns: `created_at` and `updated_at`.\n\nThe `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.\n\n#### \u003ca name=\"column-info\"\u003e\u003c/a\u003e \"Common\" Types:\n\n* `string`\n* `text`\n* `timestamp`, `time`, `datetime`\n* `integer`\n* `bool`\n* `uuid`\n\nAny other type passed it will be be passed straight through to the underlying database.\n\nFor 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!\n\n#### Supported Options:\n\n* `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})`\n* `null` - By default columns are not allowed to be `null`.\n* `default` - The default value you want for this column. By default this is `null`.\n* `default_raw` - The default value defined as a database function.\n* `after` - (MySQL Only) Add a column after another column in the table. `example: {\"after\":\"created_at\"}`\n* `first` - (MySQL Only) Add a column to the first position in the table. `example: {\"first\": true}`\n\n#### Composite primary key \n\n```javascript\ncreate_table(\"user_privileges\") {\n\tt.Column(\"user_id\", \"int\")\n\tt.Column(\"privilege_id\", \"int\")\n\tt.PrimaryKey(\"user_id\", \"privilege_id\")\n}\n```\n\nPlease note that the `t.PrimaryKey` statement MUST be after the columns definitions.\n\n### Drop a Table\n\n``` javascript\ndrop_table(\"table_name\")\n```\n\n### Rename a Table\n\n``` javascript\nrename_table(\"old_table_name\", \"new_table_name\")\n```\n\n### Add a Column\n\n``` javascript\nadd_column(\"table_name\", \"column_name\", \"string\", {})\n```\n\nSee [above](#column-info) for more details on column types and options.\n\n### Alter a column\n\n``` javascript\nchange_column(\"table_name\", \"column_name\", \"string\", {})\n```\n\n### Rename a Column\n\n``` javascript\nrename_column(\"table_name\", \"old_column_name\", \"new_column_name\")\n```\n\n### Drop a Column\n\n``` javascript\ndrop_column(\"table_name\", \"column_name\")\n```\n\n### Add an Index\n\n#### Supported Options:\n\n* `name` - This defaults to `table_name_column_name_idx`\n* `unique`\n\n#### Simple Index:\n\n``` javascript\nadd_index(\"table_name\", \"column_name\", {})\n```\n\n#### Multi-Column Index:\n\n``` javascript\nadd_index(\"table_name\", [\"column_1\", \"column_2\"], {})\n```\n\n#### Unique Index:\n\n``` javascript\nadd_index(\"table_name\", \"column_name\", {\"unique\": true})\n```\n\n#### Index Names:\n\n``` javascript\nadd_index(\"table_name\", \"column_name\", {}) # name =\u003e table_name_column_name_idx\nadd_index(\"table_name\", \"column_name\", {\"name\": \"custom_index_name\"})\n```\n\n### Rename an Index\n\n``` javascript\nrename_index(\"table_name\", \"old_index_name\", \"new_index_name\")\n```\n\n### Drop an Index\n\n``` javascript\ndrop_index(\"table_name\", \"index_name\")\n```\n\n### Add a Foreign Key\n\n```javascript\nadd_foreign_key(\"table_name\", \"field\", {\"ref_table_name\": [\"ref_column\"]}, {\n    \"name\": \"optional_fk_name\",\n    \"on_delete\": \"action\",\n    \"on_update\": \"action\",\n})\n\n```\n\n#### Supported Options\n\n* `name` - This defaults to `table_name_ref_table_name_ref_column_name_fk`\n* `on_delete` - `CASCADE`, `SET NULL`, ...\n* `on_update`\n\n**Note:** `on_update` and `on_delete` are not supported on CockroachDB yet.\n\n### Drop a Foreign Key\n\n```javascript\ndrop_foreign_key(\"table_name\", \"fk_name\", {\"if_exists\": true})\n```\n\n#### Supported Options\n\n* `if_exists` - Adds `IF EXISTS` condition\n\n\n### Raw SQL\n\n``` javascript\nsql(\"select * from users;\")\n```\n\n### Execute an External Command\n\nSometimes during a migration you need to shell out to an external command.\n\n```javascript\nexec(\"echo hello\")\n```\n\n## Development\n\n### Testing\n\nTo run end-to-end tests, use\n\n```\nmake test\n```\n\nIf you made changes to the end-to-end tests and want to update the fixtures,\nrun the following command a couple of times until tests pass:\n\n```\nREFRESH_FIXTURES=true make test\n```\n","funding_links":["https://github.com/sponsors/markbates","https://github.com/sponsors/stanislas-m","https://patreon.com/buffalo"],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobuffalo%2Ffizz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgobuffalo%2Ffizz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgobuffalo%2Ffizz/lists"}