{"id":21451733,"url":"https://github.com/moranilt/pms","last_synced_at":"2026-05-20T02:44:38.861Z","repository":{"id":65339002,"uuid":"589223979","full_name":"Moranilt/pms","owner":"Moranilt","description":"Personal Migration System. CLI and GO package.","archived":false,"fork":false,"pushed_at":"2023-01-22T06:21:21.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-23T12:29:38.044Z","etag":null,"topics":["cli","database","go","migration","package"],"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/Moranilt.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}},"created_at":"2023-01-15T13:46:18.000Z","updated_at":"2023-01-26T05:55:56.000Z","dependencies_parsed_at":"2023-02-12T14:46:37.376Z","dependency_job_id":null,"html_url":"https://github.com/Moranilt/pms","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moranilt%2Fpms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moranilt%2Fpms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moranilt%2Fpms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moranilt%2Fpms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moranilt","download_url":"https://codeload.github.com/Moranilt/pms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243964462,"owners_count":20375782,"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":["cli","database","go","migration","package"],"created_at":"2024-11-23T04:25:35.731Z","updated_at":"2026-05-20T02:44:38.792Z","avatar_url":"https://github.com/Moranilt.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Go Reference](https://pkg.go.dev/badge/github.com/Moranilt/pms.svg)](https://pkg.go.dev/github.com/Moranilt/pms)\n\n# pms\nPersonal Migration System. CLI and GO package.\n\n# Homebrew\n[Pull Request](https://github.com/Homebrew/homebrew-core/pull/120892)\n\nTo make it easier to install with Homebrew, this package should be more notable to deploy it(\u003e30 forks, \u003e=30 watchers and \u003e=75 stars). Please support this package!\n\n# Supported drivers\n- MySQL (4.1+)\n- MariaDB\n- Percona Server\n- Google CloudSQL or Sphinx (2.2.3+)\n- PostgreSQL\n\n# How to use\n\n## Install package\n```bash\ngo get github.com/Moranilt/pms\n```\n\n## Make folder\nFirst of all you should create a folder where to store migration-files:\n\n```bash\nmkdir migrations\n```\n\n## Make files\nTo create a migration file you should follow template `{version}_{any_name}.{action}.sql` where:\n- `version` - version of migrations\n- `any_name` - name which associated with queries inside(whatever you want)\n- `action` - only `up` or `down`\n\n### Example:\n```\n- 1_users.up.sql\n- 1_users.down.sql\n- 2_posts.up.sql\n- 2_posts.down.sql\n```\n\n**1_users.up.sql**:\n```sql\nCREATE TABLE users (\n  id SERIAL PRIMARY KEY,\n  name VARCHAR(255) NOT NULL,\n  email VARCHAR(255) NOT NULL\n);\n```\n\n**1_users.down.sql**:\n```sql\nDROP TABLE users;\n```\n\n**2_posts.up.sql**:\n```sql\nCREATE TABLE posts (\n  id SERIAL PRIMARY KEY,\n  user_id BIGINT NOT NULL,\n  title VARCHAR(255) NOT NULL,\n  content TEXT NOT NULL,\n  FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE\n);\n```\n\n**2_posts.down.sql**:\n```sql\nDROP TABLE posts;\n```\n\n## Run\nAfter first run it'll create `migrations` table in your DB. **Do not delete or update it!**\n### Inside of GO application\n\n#### Up\nTo run all migrations you should use `Up` method which will run all files with `up` action in file.\n\nIf current version `2` and you have files with version up to `5`, `Up` method will run all files from `3` to `5` versions.\n\nExample:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/Moranilt/pms\"\n\t\"github.com/jmoiron/sqlx\"\n)\n\nfunc main() {\n\tconn := \"host=localhost dbname=postgres user=root password=1234 port=5432 sslmode=disable\"\n\tdb, err := sqlx.Connect(\"postgres\", conn)\n\tif err != nil {\n\t\tlog.Fatal(\"error while connecting to db\", err)\n\t}\n\n\tmigrator, err := pms.New(db, \"./migrations\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\terr = migrator.Up()\n\tif err != nil {\n\t\tlog.Fatal(\"failed to run migrations: \", err)\n\t}\n}\n```\n\n#### Down\nTo run all files with `down` action you should use `Down` method. \n\nIt will run all files with `down` actions with descending order starts from the latest version of migration.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/Moranilt/pms\"\n\t\"github.com/jmoiron/sqlx\"\n)\n\nfunc main() {\n\tconn := \"host=localhost dbname=postgres user=root password=1234 port=5432 sslmode=disable\"\n\tdb, err := sqlx.Connect(\"postgres\", conn)\n\tif err != nil {\n\t\tlog.Fatal(\"error while connecting to db\", err)\n\t}\n\n\tmigrator, err := pms.New(db, \"./migrations\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\terr = migrator.Down()\n\tif err != nil {\n\t\tlog.Fatal(\"failed to run down migrations: \", err)\n\t}\n}\n```\n\n#### Version\nYou can chose the version to jump to with `Version` method. Works like checkout to specific version.\n\nIf current version is `5` and you will run `migrator.Version(7)`, it will execute all migration files with `up` action from `6` to `7` versions.\n\nIf current version is `5` and you will run `migrator.Version(2)`, it will execute all migration files with `down` action from `5` to `3` versions.\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\n\t\"github.com/Moranilt/pms\"\n\t\"github.com/jmoiron/sqlx\"\n)\n\nfunc main() {\n\tconn := \"host=localhost dbname=postgres user=root password=1234 port=5432 sslmode=disable\"\n\tdb, err := sqlx.Connect(\"postgres\", conn)\n\tif err != nil {\n\t\tlog.Fatal(\"error while connecting to db\", err)\n\t}\n\n\tmigrator, err := pms.New(db, \"./migrations\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\terr = migrator.Version(3)\n\tif err != nil {\n\t\tlog.Fatal(\"failed to run version migrations: \", err)\n\t}\n\n  \terr = migrator.Version(5)\n\tif err != nil {\n\t\tlog.Fatal(\"failed to run version migrations: \", err)\n\t}\n}\n```\n\n### CMD\nYou can find binaries for your system in [releases](https://github.com/Moranilt/pms/releases).\n\nAllowed flags:\n\n**--help** - display all available flags \\\n**-db** string - Database name \\\n**-down** - Run all down migrations from provided path \\\n**-host** string - Database host (default \"localhost\") \\\n**-pass** string - Database password \\\n**-port** int - Database port (default 5432) \\\n**-source** string - Source of migration files. For example './migrations' (default \"migrations\") \\\n**-up** - Run all migrations from provided path \\\n**-user** string - Database user (default \"root\") \\\n**-v** int - Select version of migrations (default -1) \\\n**-sslMode** string - Set ssl mode (default \"disable\") \\\n**-driver** string - Set MySQL driver (default \"mysql\") \\\n**-url** string - Connection URL. `[driver]://[user]:[pass]@[host]:[port]/[db_name]?[flag_name]=[flag_value]`\n\nExample `Up`:\n```bash\npms -driver postgres -db postgres -host localhost -pass secret_pass -source migrations -user root -up\n```\n\nExample `Down`:\n```bash\npms -db postgres -host localhost -pass secret_pass -source migrations -user root -down\n```\n\nExample `Version`:\n```bash\npms -db postgres -host localhost -pass secret_pass -source migrations -user root -v 5\n```\n\nExample URL:\n```bash\npms -driver postgres -url \"postgres://root:123456@localhost:5432/authentication?sslmode=disable\" -up\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoranilt%2Fpms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoranilt%2Fpms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoranilt%2Fpms/lists"}