{"id":18350260,"url":"https://github.com/kachit/tarantool-migrator","last_synced_at":"2025-04-09T23:51:06.019Z","repository":{"id":257827733,"uuid":"846451529","full_name":"Kachit/tarantool-migrator","owner":"Kachit","description":"Simple tarantool migrator","archived":false,"fork":false,"pushed_at":"2025-04-09T20:13:28.000Z","size":86,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T23:51:03.119Z","etag":null,"topics":["golang","migration-tool","migrations","tarantool"],"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/Kachit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T08:34:18.000Z","updated_at":"2025-04-09T20:13:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"a18be718-508b-4086-8434-ef100835b97b","html_url":"https://github.com/Kachit/tarantool-migrator","commit_stats":null,"previous_names":["kachit/tarantool-migrator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kachit%2Ftarantool-migrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kachit%2Ftarantool-migrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kachit%2Ftarantool-migrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kachit%2Ftarantool-migrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kachit","download_url":"https://codeload.github.com/Kachit/tarantool-migrator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131455,"owners_count":21052819,"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":["golang","migration-tool","migrations","tarantool"],"created_at":"2024-11-05T21:25:51.270Z","updated_at":"2025-04-09T23:51:06.000Z","avatar_url":"https://github.com/Kachit.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tarantool Migrator\n[![Go Test](https://github.com/Kachit/tarantool-migrator/actions/workflows/tests.yml/badge.svg)](https://github.com/Kachit/tarantool-migrator/actions)\n[![Codecov](https://codecov.io/github/Kachit/tarantool-migrator/graph/badge.svg)](https://codecov.io/github/Kachit/tarantool-migrator)\n[![Go Report Card](https://goreportcard.com/badge/github.com/kachit/tarantool-migrator)](https://goreportcard.com/report/github.com/kachit/tarantool-migrator)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/Kachit/tarantool-migrator)](https://go.dev/doc/go1.20)\n[![Release](https://img.shields.io/github/v/release/Kachit/tarantool-migrator.svg)](https://github.com/Kachit/tarantool-migrator/releases)\n[![GoDoc](https://img.shields.io/badge/go.dev-reference-brightgreen?logo=go\u0026logoColor=white\u0026style=flat)](https://pkg.go.dev/github.com/kachit/tarantool-migrator)\n[![License](https://img.shields.io/github/license/Kachit/tarantool-migrator)](https://github.com/Kachit/tarantool-migrator/blob/main/LICENSE)\n\n## Description\nSimple Tarantool migrator written in golang\n\n## Download\n```shell\ngo get -u github.com/kachit/tarantool-migrator\n```\n\n## Usage\n\n### Migrations as lua files\nLua migration file format: `{migration-name}.{migration-cmd}.lua`\n* `{migration-name}` - migration ID in migrations space\n* `{migration-cmd}` - (`up` or `down`) migration command\n* `--` in start of migration filename - exclude migration from list\n\n**NOTICE**: When migrations loaded from filesystem they sorted by `{migration-name}` automatically\n```\n|-- migrations\n    |-- 202410082345_test_migration_1.down.lua // 202410082345_test_migration_1 Down cmd\n    |-- 202410082345_test_migration_1.up.lua // 202410082345_test_migration_1 Up cmd\n    |-- 202410091201_test_migration_2.down.lua // 202410091201_test_migration_2 Down cmd\n    |-- 202410091201_test_migration_2.up.lua // 202410091201_test_migration_2 Up cmd\n    |-- --202410091545_test_migration_3.up.lua //excluded migration\n```\n\n### Migrations as go slice\n**NOTICE**: When migrations built as go slice they order will not change\n```go\npackage migrations\n\nimport (\n\ttarantool_migrator \"github.com/kachit/tarantool-migrator\"\n\t\"github.com/tarantool/go-tarantool/v2/pool\"\n\t\"context\"\n)\n\nvar Migrations = tarantool_migrator.MigrationsCollection{\n\t\u0026tarantool_migrator.Migration{\n\t\tID: \"202410082345_test_migration_1\",\n\t\tMigrate: func(ctx context.Context, pooler pool.Pooler, options *tarantool_migrator.Options) error {\n\t\t\t//your migration Up code here\n\t\t\treturn nil\n\t\t},\n\t\tRollback: func(ctx context.Context, pooler pool.Pooler, options *tarantool_migrator.Options) error {\n\t\t\t//your migration Down code here\n\t\t\treturn nil\n\t\t},\n\t},\n}\n```\n\n### Migrations in tarantool\n\nBy default, tarantool migrations stored in `migrations` space, but you can change it in options\n\nExample:\n\n| **id**                        | **executed_at**                       |\n|-------------------------------|---------------------------------------|\n| 202410082345_test_migration_1 | 2024-10-11 20:33:28.3860465 +0000 UTC |\n| 202410091201_test_migration_2 | 2024-10-11 20:33:28.3860465 +0000 UTC |\n\n### Let's connect to tarantool\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"time\"\n\t\"context\"\n\t\"github.com/tarantool/go-tarantool/v2\"\n\t\"github.com/tarantool/go-tarantool/v2/pool\"\n)\n\nfunc main(){\n\t//Your tarantool config\n\tconfig := \u0026TarantoolConfig{\n\t\tHost:     \"127.0.0.1\",\n\t\tPort:     3301,\n\t\tLogin:    \"login\",\n\t\tPassword: \"password\",\n\t}\n\tctx := context.Background()\n\tdialer := tarantool.NetDialer{\n\t\tAddress:  fmt.Sprintf(\"%s:%d\", config.Host, config.Port),\n\t\tUser:     config.Login,\n\t\tPassword: config.Password,\n\t}\n\topts := tarantool.Opts{\n\t\tTimeout:   time.Second,\n\t\tReconnect: 2 * time.Second,\n\t}\n\t\n\t//connect to tarantool pool\n\tinstance1 := pool.Instance{Name: \"your-instance-address\", Dialer: dialer, Opts: opts}\n\ttt, err :=  pool.Connect(ctx, []pool.Instance{\n\t\tinstance1,\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n### Let's starting migrate\n```go\npackage main\n\nimport (\n\t\"embed\"\n\t\"context\"\n\ttarantool_migrator \"github.com/kachit/tarantool-migrator\"\n)\n\n//go:embed migrations\nvar LuaFs embed.FS\n\nfunc main(){\n\tctx := context.Background()\n\t//load migrations list from embed\n\tfsLoader := tarantool_migrator.NewEmbedFsLoader(LuaFs)\n\tmigrations, err := fsLoader.LoadMigrations(\"migrations\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t//migrate\n\tmigrator := tarantool_migrator.NewMigrator(tt, migrations)\n\terr = migrator.Migrate(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n### Let's rollback latest migration\n```go\npackage main\n\nimport (\n\t\"embed\"\n\t\"context\"\n\ttarantool_migrator \"github.com/kachit/tarantool-migrator\"\n)\n\n//go:embed migrations\nvar LuaFs embed.FS\n\nfunc main(){\n\tctx := context.Background()\n\t//load migrations list from embed\n\tfsLoader := tarantool_migrator.NewEmbedFsLoader(LuaFs)\n\tmigrations, err := fsLoader.LoadMigrations(\"migrations\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t//rollback last applied migration (202410091201_test_migration_2)\n\tmigrator := tarantool_migrator.NewMigrator(tt, migrations)\n\terr = migrator.RollbackLast(ctx)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n## Coverage\n```bash\ngo test --coverprofile=coverage.out ./... ; go tool cover -func coverage.out ; go tool cover --html=coverage.out -o coverage.html\n```\n\n## Linters ##\n```bash\ngolangci-lint run\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkachit%2Ftarantool-migrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkachit%2Ftarantool-migrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkachit%2Ftarantool-migrator/lists"}