{"id":15808379,"url":"https://github.com/kota65535/alternator","last_synced_at":"2025-05-07T08:14:00.214Z","repository":{"id":47112193,"uuid":"486271457","full_name":"kota65535/alternator","owner":"kota65535","description":"Declarative SQL database schema management by human-friendly pure SQL.","archived":false,"fork":false,"pushed_at":"2025-05-06T18:58:11.000Z","size":239,"stargazers_count":6,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-07T08:13:53.633Z","etag":null,"topics":["database","go","golang","mysql","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/kota65535.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-04-27T16:31:42.000Z","updated_at":"2024-12-26T14:11:01.000Z","dependencies_parsed_at":"2022-08-27T07:01:30.394Z","dependency_job_id":"58c95673-5f16-4fc2-b0e9-bc5fe150cf2e","html_url":"https://github.com/kota65535/alternator","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kota65535%2Falternator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kota65535%2Falternator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kota65535%2Falternator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kota65535%2Falternator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kota65535","download_url":"https://codeload.github.com/kota65535/alternator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252839296,"owners_count":21812089,"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":["database","go","golang","mysql","sql"],"created_at":"2024-10-05T03:01:52.916Z","updated_at":"2025-05-07T08:14:00.189Z","avatar_url":"https://github.com/kota65535.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alternator\n\nDeclarative SQL database schema management by human-friendly pure SQL.\n\n- 100% pure SQL schema file\n- Diff visualization between a schema file and actual database schemas\n- Automatic generation and execution of ALTER statements to apply the schema\n- No need to \"import\" redundant schemas from the database: write your own way\n\n## Supported databases\n\n- MySQL (8.x, 5.x)\n\n## Install\n\n### Mac\n\n```bash\nbrew tap kota65535/alternator\nbrew install alternator\n```\n\n### Linux \u0026 Windows\n\nDownload the binary from [GitHub Releases](https://github.com/kota65535/alternator/releases/latest) and drop it in\nyour `$PATH`.\n\n## Getting Started\n\n1. Create a schema file. As an example here, we create `schema.sql` with the following content.\n\n```sql\nCREATE DATABASE example;\nUSE example;\nCREATE TABLE users\n(\n    id   int PRIMARY KEY,\n    name varchar(100)\n);\nCREATE TABLE blog_posts\n(\n    id        int PRIMARY KEY,\n    title     varchar(100),\n    body      text,\n    author_id int,\n    FOREIGN KEY (author_id) REFERENCES users (id)\n);\n```\n\n2. Run the schema file to create a database and tables.\n\n```sh\nmysql -u root \u003c schema.sql\n```\n\n3. Run `alternator plan` to verify the schema is up-to-date.\n\n```sh\nalternator plan schema.sql mysql://root@localhost/example\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow Output\u003c/summary\u003e\n\n```\nFetching schemas of database 'example'...\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nSchema diff:\n\n  CREATE DATABASE `example`;\n\n  CREATE TABLE `example`.`users`\n  (\n      `id`   int          NOT NULL,\n      `name` varchar(100),\n      PRIMARY KEY (`id`)\n  );\n\n  CREATE TABLE `example`.`blog_posts`\n  (\n      `id`        int          NOT NULL,\n      `title`     varchar(100),\n      `body`      text,\n      `author_id` int,\n      PRIMARY KEY (`id`),\n      CONSTRAINT `blog_posts_ibfk_1` FOREIGN KEY `author_id` (`author_id`) REFERENCES `users` (`id`)\n  );\n\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nYour database schema is up-to-date! No change required.\n```\n\n\u003c/details\u003e\n\n4. Now let's modify the schema file.\n\n```sql\nCREATE DATABASE example;\nUSE example;\nCREATE TABLE users\n(\n    id   int PRIMARY KEY AUTO_INCREMENT, # add AUTO_INCREMENT\n    name varchar(100),\n    INDEX (name)                         # added\n);\nCREATE TABLE blog_posts\n(\n    id        int PRIMARY KEY,\n    title     varchar(200), # modify length 100 -\u003e 200\n    content   text,         # rename body -\u003e content\n    author_id int,\n    FOREIGN KEY (author_id) REFERENCES users (id)\n);\nCREATE TABLE categories # added\n(\n    id   int PRIMARY KEY,\n    name varchar(100)\n);\n```\n\n5. Run `alternator plan` to show the schema diff and SQL statements that should be executed.\n   Note that the foreign key `author_id` should be recreated because of the modification of the referencing key.\n\n```sh\nalternator plan schema.sql mysql://root@localhost/example\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow Output\u003c/summary\u003e\n\n```diff\nFetching schemas of database 'example'...\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nSchema diff:\n\n  CREATE DATABASE `example`;\n\n  CREATE TABLE `example`.`users`\n  (\n!     `id`   int          NOT NULL -\u003e `id` int NOT NULL AUTO_INCREMENT,\n      `name` varchar(100),\n      PRIMARY KEY (`id`),\n+     INDEX (`name`)\n  );\n\n  CREATE TABLE `example`.`blog_posts`\n  (\n      `id`        int          NOT NULL,\n!     `title`     varchar(100)          -\u003e `title`   varchar(200),\n!     `body`      text                  -\u003e `content` text,\n      `author_id` int,\n      PRIMARY KEY (`id`),\n-     CONSTRAINT `blog_posts_ibfk_1` FOREIGN KEY `author_id` (`author_id`) REFERENCES `users` (`id`),\n+     FOREIGN KEY (author_id) REFERENCES users (id)\n  );\n\n+ CREATE TABLE `example`.`categories`\n+ (\n+     `id`   int          NOT NULL,\n+     `name` varchar(100),\n+     PRIMARY KEY (`id`)\n+ );\n\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nStatements to execute:\n\nALTER TABLE `example`.`users` ADD INDEX (`name`);\nALTER TABLE `example`.`blog_posts` MODIFY COLUMN `title` varchar(200);\nALTER TABLE `example`.`blog_posts` CHANGE COLUMN `body` `content` text;\nALTER TABLE `example`.`blog_posts` DROP FOREIGN KEY `blog_posts_ibfk_1`;\nALTER TABLE `example`.`blog_posts` DROP INDEX `author_id`;\nALTER TABLE `example`.`users` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT;\nALTER TABLE `example`.`blog_posts` ADD FOREIGN KEY (`author_id`) REFERENCES `users` (`id`);\nCREATE TABLE `example`.`categories`\n(\n    `id`   int          NOT NULL,\n    `name` varchar(100),\n    PRIMARY KEY (`id`)\n);\n```\n\n\u003c/details\u003e\n\n6. Run `alternator apply` to apply the schema change by executing planned SQL statements.\n\n```sh\nalternator apply schema.sql mysql://root@localhost/example\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eShow Output\u003c/summary\u003e\n\n```\nFetching schemas of database 'example'...\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nStatements to execute:\n\nALTER TABLE `example`.`users` ADD INDEX (`name`);\nALTER TABLE `example`.`blog_posts` MODIFY COLUMN `title` varchar(200);\nALTER TABLE `example`.`blog_posts` CHANGE COLUMN `body` `content` text;\nALTER TABLE `example`.`blog_posts` DROP FOREIGN KEY `blog_posts_ibfk_1`;\nALTER TABLE `example`.`blog_posts` DROP INDEX `author_id`;\nALTER TABLE `example`.`users` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT;\nALTER TABLE `example`.`blog_posts` ADD FOREIGN KEY (`author_id`) REFERENCES `users` (`id`);\nCREATE TABLE `example`.`categories`\n(\n    `id`   int          NOT NULL,\n    `name` varchar(100),\n    PRIMARY KEY (`id`)\n);\n\n――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――\nDo you want to apply? [y/n]: y\nExecuting: ALTER TABLE `example`.`users` ADD INDEX (`name`);\nExecuting: ALTER TABLE `example`.`blog_posts` MODIFY COLUMN `title` varchar(200);\nExecuting: ALTER TABLE `example`.`blog_posts` CHANGE COLUMN `body` `content` text;\nExecuting: ALTER TABLE `example`.`blog_posts` DROP FOREIGN KEY `blog_posts_ibfk_1`;\nExecuting: ALTER TABLE `example`.`blog_posts` DROP INDEX `author_id`;\nExecuting: ALTER TABLE `example`.`users` MODIFY COLUMN `id` int NOT NULL AUTO_INCREMENT;\nExecuting: ALTER TABLE `example`.`blog_posts` ADD FOREIGN KEY (`author_id`) REFERENCES `users` (`id`);\nExecuting: CREATE TABLE `example`.`categories`\n(\n    `id`   int          NOT NULL,\n    `name` varchar(100),\n    PRIMARY KEY (`id`)\n);\n\nFinished!\n```\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkota65535%2Falternator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkota65535%2Falternator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkota65535%2Falternator/lists"}