{"id":16527941,"url":"https://github.com/igorkamyshev/trona","last_synced_at":"2025-09-11T07:32:21.462Z","repository":{"id":37791228,"uuid":"139429839","full_name":"igorkamyshev/trona","owner":"igorkamyshev","description":"Write DB migrations with SQL and run them with a CLI","archived":false,"fork":false,"pushed_at":"2023-01-16T20:09:14.000Z","size":16929,"stargazers_count":30,"open_issues_count":21,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-03T07:23:02.868Z","etag":null,"topics":["database","evolution","migration","node"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/igorkamyshev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-07-02T10:45:03.000Z","updated_at":"2024-09-03T11:31:57.000Z","dependencies_parsed_at":"2023-02-10T06:01:03.697Z","dependency_job_id":null,"html_url":"https://github.com/igorkamyshev/trona","commit_stats":null,"previous_names":["solid-soda/trona-evolutions"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/igorkamyshev/trona","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Ftrona","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Ftrona/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Ftrona/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Ftrona/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/igorkamyshev","download_url":"https://codeload.github.com/igorkamyshev/trona/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/igorkamyshev%2Ftrona/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274595108,"owners_count":25314015,"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-09-11T02:00:13.660Z","response_time":74,"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":["database","evolution","migration","node"],"created_at":"2024-10-11T17:37:31.191Z","updated_at":"2025-09-11T07:32:21.126Z","avatar_url":"https://github.com/igorkamyshev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# trona\n\nThis library allows you to write migration scenarios using SQL and run them with a simple CLI.\n\n- **Simple**: only plain SQL\n- **Lightweight**: only 5.6 kB in node_modules\n- **Modern**: ESM support out of the box\n\n## Usage example\n\n```console\nfoo@bar:~$ yarn trona\n\nRunning evolve script\n\n--- 1.sql ---\n\nCREATE TABLE Customers (\n    id   INTEGER     NOT NULL,\n    name VARCHAR(32) NOT NULL,\n    primary key (id)\n);\n\nEvolution is successful!\n\nfoo@bar:~$\n```\n\n## Installation\n\nFirst you need to install `trona` via package manager:\n\n```console\nyarn add trona\n```\n\n## Configuration\n\nThen you need to setup simple configuration file named `.trona-config.js` and containing script that exports async function `runQuery`. The function should be rejected in case of failure of said query and in case of SELECT query successfully executed returns array of selected rows in form of an object `{[field]: value}`.\n\n### PostgreSQL example\n\n```javascript\nimport PG from 'pg';\n\nconst client = new PG.Client({\n  // ...\n});\n\nawait client.connect();\nconsole.log(`Connected to database`);\n\nexport function runQuery(query) {\n  return client.query(query).then((result) =\u003e result.rows);\n}\n```\n\n### MySQL example\n\n```javascript\nimport mysql from 'mysql';\nimport { promisify } from 'util';\n\nconst connection = mysql.createConnection({\n  // ...\n});\n\nconst connect = promisify(connection.connect).bind(connection);\nconst runQuery = promisify(connection.query).bind(connection);\n\nawait connect();\nconsole.log(`Connected to database`);\n\nexport { runQuery };\n```\n\n## Write evolutions\n\nCreate a folder `evolutions` for your evolutions script and add your first evolution to it. Note the rules which you should follow writing said evolutions:\n\n1. Name file `{evolution-number}-{text}.sql`. Text part `-{text}` is optional and can be omitted (e.g. both `1.sql` and `1-create-table.sql` are correct). Note: file name should always start with number. Evolution script file with any other symbol will be ignored (e.g. `*1-incorrect.sql` or `-1-worng.sql`) and warning will be shown during execution.\n2. Complement evolution file with fallback scripts. Separate evolution and fallback scripts with \"#DOWN\" comment as it show in example below.\n3. Execution will not be started in case of any conflict of numbering is found (e.g. existing any of two: `1-abba.sql`, `1-baab.sql`, `1.sql`, `1-baba.sql`)\n\nFolder content example:\n\n```\n- evolutions\n    - 1.sql\n    - 2.sql\n    - 3.sql\n    ...\n```\n\nEvolution contents example:\n\n```sql\nCREATE TABLE Customers (\n    id   INTEGER     NOT NULL,\n    name VARCHAR(32) NOT NULL,\n    primary key (id)\n);\n\n#DOWN\n\nDROP TABLE Customers;\n```\n\nRun command\n\n```console\nyarn trona\n```\n\nThis command will create table with information about evolutions, if it doesn't exist. After it will execute all your evolutions.\n\n## Usage\n\nAfter you managed to successfully setup `trona` you can run `yarn trona` command. This command will automatically detect any changed or new files in your evolutions folder, run respected fallback scripts if needed and than evolve your databae schema (e. g. if you have 1.sql, 2.sql, and 3.sql evolutions already in your database, you have changed 2.sql and added 4.sql it will run fallback for 3.sql and 2.sql and then run 2.sql, 3.sql, and 4.sql scripts)\n\n## Options\n\n### Interactivity\n\nBy default evolution script will ask for a confirmation to run a degrade script. You can disable this feature by `-y` or `--no-interactive` flag.\n\n```console\nyarn trona -y\n```\n\n### Config\n\nYou can change path to trona config file by providing `-c` or `--config-path` option (by default trona will try to find config file `.trona-config.js` in a root directory).\n\n```console\nyarn trona -c config/.trona-my-config.js\n```\n\n### Custom evolutions folder\n\nCustom evolutions folder can be choosen by providing `-d` or `--evolutions-dir` option. By default `evolutions` folder is being used.\n\n```console\nyarn trona -d migrations\n```\n\n## Maintenance\n\n### Release flow\n\n1. Bump `version` in [package.json](./package.json)\n2. Fill [CHANGELOG.md](./CHANGELOG.md)\n3. Commit changes by `git commin -m \"Release X.X.X\"`\n4. Create git tag for release by `git tag -a vX.X.X -m \"vX.X.X\"`\n5. Push changes to remote by `git push --follow-tags`\n6. Release package to registry by `yarn clean-publish`\n7. Fill release page with changelog on GitHub\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkamyshev%2Ftrona","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Figorkamyshev%2Ftrona","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Figorkamyshev%2Ftrona/lists"}