{"id":13763503,"url":"https://github.com/emvi/gondolier","last_synced_at":"2025-05-10T17:30:35.131Z","repository":{"id":57496812,"uuid":"107387321","full_name":"emvi/gondolier","owner":"emvi","description":"Gondolier is a database migration library for Go.","archived":true,"fork":false,"pushed_at":"2019-05-14T14:13:29.000Z","size":67,"stargazers_count":29,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-06T05:49:04.342Z","etag":null,"topics":["auto","database","golang","gondolier","library","migration","postgres","sql"],"latest_commit_sha":null,"homepage":"https://godoc.org/github.com/emvicom/gondolier","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/emvi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-18T09:33:59.000Z","updated_at":"2025-02-28T03:01:50.000Z","dependencies_parsed_at":"2022-09-03T03:33:46.723Z","dependency_job_id":null,"html_url":"https://github.com/emvi/gondolier","commit_stats":null,"previous_names":["emvicom/gondolier"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emvi%2Fgondolier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emvi%2Fgondolier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emvi%2Fgondolier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emvi%2Fgondolier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emvi","download_url":"https://codeload.github.com/emvi/gondolier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253453148,"owners_count":21911049,"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":["auto","database","golang","gondolier","library","migration","postgres","sql"],"created_at":"2024-08-03T15:00:49.356Z","updated_at":"2025-05-10T17:30:34.726Z","avatar_url":"https://github.com/emvi.png","language":"Go","funding_links":[],"categories":["数据库","Database","数据库  `go语言实现的数据库`"],"sub_categories":["标准 CLI","Advanced Console UIs"],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"gondoliergopher.svg\" width=\"300px\" /\u003e\n\u003c/p\u003e\n\n# Gondolier\n\n[![GoDoc](https://godoc.org/github.com/emvi/gondolier?status.svg)](https://godoc.org/github.com/emvi/gondolier)\n[![CircleCI](https://circleci.com/gh/emvi/gondolier.svg?style=svg)](https://circleci.com/gh/emvi/gondolier)\n[![Go Report Card](https://goreportcard.com/badge/github.com/emvi/gondolier)](https://goreportcard.com/report/github.com/emvi/gondolier)\n\n## Description\n\nGondolier is a library to auto migrate database schemas in Go (golang) using structs. Quick demo:\n\n```\ntype Customer struct {\n    Id   uint64 `gondolier:\"type:bigint;id\"`\n    Name string `gondolier:\"type:varchar(255);notnull\"`\n    Age  int    `gondolier:\"type:integer;notnull\"`\n}\n\ntype Order struct {\n    Id    uint64 `gondolier:\"type:bigint;id\"`\n    Buyer uint64 `gondolier:\"type:bigint;fk:customer.id;notnull\"`\n}\n\ntype OrderPosition struct {\n    Id       uint64 `gondolier:\"type:bigint;id\"`\n    Order    uint64 `gondolier:\"type:bigint;fk:order.id;notnull\"`\n    Quantity int    `gondolier:\"type:integer;notnull\"`\n    Cost     int    `gondolier:\"type:integer;notnull\"`\n}\n\ntype Obsolete struct{}\n\nfunc main() {\n    // connect to database\n    db, _ := sql.Open(\"postgres\", dbString())\n    defer db.Close()\n\n    // migrate your schema\n    gondolier.Use(db, \u0026gondolier.Postgres{Schema: \"public\",\n        DropColumns: true,\n        Log:         true})\n    gondolier.Model(Customer{}, Order{}, OrderPosition{})\n    gondolier.Drop(Obsolete{})\n    gondolier.Migrate()\n}\n```\n\n[View the full demo](https://github.com/emvi/gondolier-example)\n\n### Features\n\n* create and update your database schema just from your data model defined in Go\n* drop columns when they're no longer needed (removed in struct)\n* drop tables by passing a struct (which can be empty)\n\n#### Supported databases\n\n* Postgres\n\n### Limits\n\n* no multi primary key support yet\n* there is no way Gondolier can check if the data model is valid, so it might fail to execute the migration (with a panic)\n\n## Installation\n\nTo install Gondolier, go get all dependencies and Gondolier:\n\n```\ngo get github.com/lib/pq # for Postgres\ngo get github.com/emvi/gondolier\n```\n\n## Usage\n\nGondolier consists only out of a few methods. First, you set up Gondolier by passing the database connection and the migrator to *Use*:\n\n```\ngondolier.Use(dbconn, migrator)\n```\n\nThe migrator is an interface which is used by Gondolier to migrate the data model. Example:\n\n```\ngondolier.Postgres{Schema: \"public\", DropColums: true, Log: true}\n```\n\nThis will configure the Postgres migrator to use the schema \"public\", drop columns when the field is missing in the data model and output executed SQL statements to log (using the standard log library).\n\nNow you can define a naming schema used to name tables and columns:\n\n```\ngondolier.Naming(\u0026gondolier.SnakeCase{})\n```\n\nYou can define your own naming schema by implementing the NameSchema interface. Currently SnakeCase is the default. You don't need to call *Naming* to set it.\n\nNow call *Model* and pass the models which define your database schema:\n\n```\ngondolier.Model(MyModel{}, \u0026AnotherModel{})\n```\n\n*Model* accepts objects and pointers. The models must define a decorator with meta information. For more details take a look at the Postgres Migrator or the example implementation. Here is a short example:\n\n```\ntype MyModel struct {\n    Id       uint64 `gondolier:\"type:bigint;id\"` // id is a shortcut\n    SomeAttr string `gondolier:\"type:text;notnull\"`\n}\n\ntype AnotherModel struct {\n    Id         uint64   `gondolier:\"type:bigint;pk;seq:1,1,-,-,1;default:nextval(seq);notnull\"` // long version for \"id\"\n    UniqueAttr int      `gondolier:\"type:integer;notnull;unique;default:42\"`\n    AnArray    []string `gondolier:\"type:varchar(100)[]\"`\n    ForeignKey uint64   `gondolier:\"type:bigint;fk:MyModel.Id;notnull\"`\n}\n```\n\nAfterwards, call *Migrate* to start the migration:\n\n```\ngondolier.Migrate()\n```\n\nTo drop a table that is no longer needed, call *Drop*. You can remove all attributes from the struct, only the name must match the old struct:\n\n```\ntype DropMe struct {}\ngondolier.Drop(DropMe{})\n```\n\n## Contribute\n\n[See CONTRIBUTING.md](CONTRIBUTING.md)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femvi%2Fgondolier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femvi%2Fgondolier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femvi%2Fgondolier/lists"}