{"id":23873095,"url":"https://github.com/corverroos/truss","last_synced_at":"2026-05-20T14:01:36.822Z","repository":{"id":57543405,"uuid":"294890034","full_name":"corverroos/truss","owner":"corverroos","description":"Truss is a simple golang mysql schema management library","archived":false,"fork":false,"pushed_at":"2021-05-14T11:50:47.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T20:14:03.971Z","etag":null,"topics":["golang","golang-library","mysql","schema","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/corverroos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-12T07:04:53.000Z","updated_at":"2023-05-16T09:49:12.000Z","dependencies_parsed_at":"2022-08-27T19:10:38.089Z","dependency_job_id":null,"html_url":"https://github.com/corverroos/truss","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/corverroos/truss","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corverroos%2Ftruss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corverroos%2Ftruss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corverroos%2Ftruss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corverroos%2Ftruss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/corverroos","download_url":"https://codeload.github.com/corverroos/truss/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/corverroos%2Ftruss/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270781204,"owners_count":24643806,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["golang","golang-library","mysql","schema","sql"],"created_at":"2025-01-03T16:39:39.635Z","updated_at":"2026-05-20T14:01:31.765Z","avatar_url":"https://github.com/corverroos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# truss\n\n\u003e truss /trŭs/\n\u003e\n\u003e  n. A rigid framework, as of wooden beams or metal bars, designed to support a structure, such as a roof.\n\u003e  \n\u003e  v. to support, strengthen, or stiffen by or as if by a truss.\n\nTruss is a simple golang mysql schema management library that provides the following features:\n- `truss.Connect` returns a `*sql.DB` for a production use.\n- `truss.Migrate` schema management via migration queries (roll forward only). \n- `truss.ConnectForTesting` returns testing `*sql.DB` for a temp database with the current schema.\n- `truss.TestSchema` provides a snapshot of the current schema for explicit tracking of changes and to quickly view the current state.\n\n## TL;DR\n\nCommon usage is to use `truss` in your `db` package:\n\nDefine a simple slice of migration queries in `db/migrations.go`.\n```go\npackage db\n\n// migrations is an append-only list of all migrations over time.\nvar migrations = []string{`\n\nCREATE TABLE users (\n  id BIGINT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  type INT NOT NULL,\n\n  PRIMARY KEY (id),\n  INDEX by_name (name)\n);`, `\n\nALTEST TABLE users ADD COLUMN surname VARCHAR(255) AFTER name;\n`,\n}\n```\n\nEnsure the latest schema is applied on startup and in tests in `db/db.go`.\n```go\n// Connect returns a database connection and ensures latest migrations are applied\nfunc Connect(uri string) (*sql.DB, error) {\n\tdbc, err := truss.Connect(uri)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\terr = truss.Migrate(context.Background(), dbc, migrations)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn dbc, nil\n}\n\n// ConnectForTesting returns a database connection for a temp database with latest schema. \nfunc ConnectForTesting(t *testing.T) *sql.DB {\n\treturn truss.ConnectForTesting(t, migrations...)\n}\n```\n\nMaintain an explicit snapshot of the latest schema in `migrations_test.go`.\n```go\npackage db\n\nvar update = flag.Bool(\"update\", false, \"update schema file\")\n\n//go:generate go test -update -run=TestSchema\n\nfunc TestSchema(t *testing.T) {\n\ttruss.TestSchema(t, \"schema.sql\", *update, migrations...)\n}\n```\n\nWhich will generate the following `db/schema.sql` file that is checked into the git. \n```sql\n-- Schema generated by truss. DO NOT EDIT.\n\nCREATE TABLE `users` (\n  `id` bigint(20) NOT NULL AUTO_INCREMENT,\n  `name` varchar(255) NOT NULL,\n  `surname` varchar(255),\n  `type` int(11) NOT NULL,\n  `created_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`),\n  KEY `by_name` (`name`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4\n\nCREATE TABLE `migrations` (\n  `id` bigint(20) NOT NULL AUTO_INCREMENT,\n  `query_hash` char(64) NOT NULL,\n  `schema_hash` char(64) NOT NULL,\n  `created_at` datetime(3) NOT NULL,\n  PRIMARY KEY (`id`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorverroos%2Ftruss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcorverroos%2Ftruss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcorverroos%2Ftruss/lists"}