{"id":20795687,"url":"https://github.com/graze/morphism","last_synced_at":"2025-05-06T07:39:53.897Z","repository":{"id":20508683,"uuid":"23787286","full_name":"graze/morphism","owner":"graze","description":"Tool for parsing, extracting, and diffing mysqldump files","archived":false,"fork":false,"pushed_at":"2024-05-01T12:38:29.000Z","size":366,"stargazers_count":6,"open_issues_count":7,"forks_count":0,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-05-02T04:41:24.991Z","etag":null,"topics":["database","mysql","mysqldump","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/graze.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2014-09-08T10:45:19.000Z","updated_at":"2024-05-01T12:37:42.000Z","dependencies_parsed_at":"2024-05-01T11:10:18.857Z","dependency_job_id":"1b0eed65-ca06-4d4c-97cc-5358206f424c","html_url":"https://github.com/graze/morphism","commit_stats":{"total_commits":149,"total_committers":13,"mean_commits":"11.461538461538462","dds":0.6577181208053691,"last_synced_commit":"d274d74e2662620f8bec5dbbd13779a2f02127c5"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fmorphism","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fmorphism/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fmorphism/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graze%2Fmorphism/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graze","download_url":"https://codeload.github.com/graze/morphism/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225063013,"owners_count":17415005,"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","mysql","mysqldump","php"],"created_at":"2024-11-17T16:23:19.615Z","updated_at":"2024-11-17T16:23:20.270Z","avatar_url":"https://github.com/graze.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# morphism\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/graze/morphism.svg?style=flat-square)](https://packagist.org/packages/graze/morphism)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/graze/morphism/master.svg?style=flat-square)](https://travis-ci.org/graze/morphism)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/graze/morphism.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/morphism/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/graze/morphism.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/morphism)\n[![Total Downloads](https://img.shields.io/packagist/dt/graze/morphism.svg?style=flat-square)](https://packagist.org/packages/graze/morphism)\n[![PHP Version](https://img.shields.io/packagist/php-v/graze/morphism.svg?style=flat-square)](https://php.net)\n[![MicroBadger Size](https://img.shields.io/microbadger/image-size/graze/morphism.svg?style=flat-square)](https://microbadger.com/images/graze/morphism)\n\n\u003cimg src=\"http://i.imgur.com/QSX6EUj.gif\" alt=\"Morph and Chas\" align=\"right\" /\u003e\n\nThis package provides a set of tools for parsing, extracting, and diffing mysqldump\nfiles.\n\nA typical application of this is for managing schema changes during application\ndevelopment (keeping schemas in sync with code when switching branches), and during\ndeployment (migrating the schema to match the deployed code).\n\nUsing this tool allows you to store the complete database schema in the repository.\nWhen a branch\nrequires a schema update to work properly, you should edit your checkout's schema\nand run the new tool to figure out the necessary `ALTER` / `CREATE` / `DROP` statements\nto run, and apply them. Similarly, when switching branches you can simply run the\ntool and it will apply the necessary changes automatically.\n\nThis has the additional benefit that the complete history of the schema is stored\nunder version control, instead of a series of incremental change scripts. If more\nthan one party changes the same table, git will merge the changes automatically,\nor generate a conflict for manual merging where it cannot. All the usual git tools\nbecome useful - e.g. a simple `git annotate schema/catalog/product.sql` can tell\nyou who added a redundant index on `pr_name`.\n\n## Install\n\nVia Composer\n\n``` bash\n$ composer require graze/morphism\n```\n\n## Running With Docker\n\n```bash\n$ docker run --rm graze/morphism\n```\n\n### Examples:\n\n```bash\n$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:cached graze/morphism diff config/morphism.yml\n$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:delegated graze/morphism dump config/morphism.yml\n```\n\n### Attaching to an existing network when developing\n\nYou can add morphism to your `docker-compose` file and can talk to your databases locally.\nOr if you have an existing docker network you can do:\n\n```bash\n$ docker run --rm -v $PWD/config:/app/config -v $PWD/schema:/app/schema:cached --network app_default graze/morphsim diff config/morphism.yml\n```\n\n## Tools\n\nAll commands support the `--help` parameter which give more information on usage.\n\n* **morphism extract**: Extract schema definitions from a mysqldump file.\n* **morphism dump**: Dump database schema for a named database connection.\n* **morphism lint**: Check database schema files for correctness.\n* **morphism diff**: Show necessary DDL statements to make a given database match the schema files. Optionally apply the changes too.\n\n## Config File\n\nThe config file used by some of morphism's tools uses yaml format, as follows:\n\n```\n# All connection definitions appear under the 'databases' key\ndatabases:\n    # name of connection\n    catalog:\n        # Connection details - this is just an example, you may want to specify\n        # different properties, e.g. if connecting to a remote server. You are\n        # advised to refer to the 'pdo' documentation for further details.\n        user: 'my-user'\n        password: 'my-password'\n        host: 'localhost'\n        driver: 'pdo_mysql'\n        unix_socket: '/var/lib/mysql/catalog.sock'\n        # morphism specific options\n        morphism:\n            # morphism diff only operates on connections with 'enable: true'\n            enable: true\n            # Path where schema files live.\n            # Defaults to \"schema/\u003cconnection-name\u003e\"\n            schemaDefinitionPath:\n                - schema/catalog\n            # you may optionally specify one or more regexes matching tables\n            # to exclude (any changes, creation or deletion of matching tables\n            # will be ignored). The regex must match the entire table name, i.e.\n            # it is implicitly anchored with ^...$\n            exclude:\n                - temp_.*\n                - page_load_\\d{4}-\\d{2}-\\d{2}\n            # similarly, you may optionally specify tables for explicit inclusion.\n            include:\n                ...\n    # you may specify more connections\n    ...\n# other top level keys are ignored\n...\n```\n\n## Example Usage\n\nThis example uses `morphism dump` to generate schema files from a database, `morphism lint` for checking the files and `morphism diff` to apply changes both interactively and automatically.\n\n```\n(master) $ # create a baseline for the schema\n(master) $ mkdir schema\n(master) $ bin/morphism dump --write config.yml catalog\n(master) $ git add schema/catalog\n(master) $ git commit -m \"initial checkin of catalog schema\"\n(master) $\n(master) $ # start work on changes to the catalog...\n(master) $ git checkout -b catalog-fixes\n(catalog-fixes) $ vi schema/catalog/product.sql             # edit table definition\n(catalog-fixes) $ vi schema/catalog/product_dimensions.sql  # add new table\n(catalog-fixes) $ bin/morphism lint schema/catalog   # check syntax\nERROR schema/catalog/product_dimensions.sql, line 2: unknown datatype 'intt'\n1: CREATE TABLE product_dimensions (\n2:   `pd_id` intt\u003c\u003cHERE\u003e\u003e(10) unsigned NOT NULL AUTO_INCREMENT,\n(catalog-fixes) $ vi schema/catalog/product_dimensions.sql  # fix table definition\n(catalog-fixes) $ bin/morphism lint schema/catalog   # check syntax\n(catalog-fixes) $ git add schema/catalog\n(catalog-fixes) $ git rm schema/catalog/discontinued.sql    # delete a table\n(catalog-fixes) $ git commit -m \"various changes to catalog schema\"\n(catalog-fixes) $ # alter the database to match the schema files\n(catalog-fixes) $ bin/morphism diff --apply-changes=confirm config.yml catalog\n-- --------------------------------\n--   Connection: catalog\n-- --------------------------------\nDROP TABLE IF EXISTS `discontinued`;\n\nALTER TABLE `product`\nMODIFY COLUMN `pr_name` varchar(255) NOT NULL,\nMODIFY COLUMN `pr_description` text NOT NULL,\nADD COLUMN `pr_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `pr_description`;\n\nCREATE TABLE `product_dimensions` (\n  `pd_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `pd_width` decimal(10,2) NOT NULL,\n  `pd_height` decimal(10,2) NOT NULL,\n  `pd_depth` decimal(10,2) NOT NULL,\n  PRIMARY KEY (`pd_id`)\n) ENGINE=InnoDB;\n\n-- Confirm changes to catalog:\n\nDROP TABLE IF EXISTS `discontinued`;\n\n-- Apply this change? [y]es [n]o [a]ll [q]uit: y\n\nALTER TABLE `product`\nMODIFY COLUMN `pr_name` varchar(255) NOT NULL,\nMODIFY COLUMN `pr_description` text NOT NULL,\nADD COLUMN `pr_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `pr_description`;\n\n-- Apply this change? [y]es [n]o [a]ll [q]uit: y\n\nCREATE TABLE `product_dimensions` (\n  `pd_id` int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `pd_width` decimal(10,2) NOT NULL,\n  `pd_height` decimal(10,2) NOT NULL,\n  `pd_depth` decimal(10,2) NOT NULL,\n  PRIMARY KEY (`pd_id`)\n) ENGINE=InnoDB;\n\n-- Apply this change? [y]es [n]o [a]ll [q]uit: y\n(catalog-fixes) $ # hack hack hack\n(catalog-fixes) $ ...\n(catalog-fixes) $ # do some work back on master...\n(catalog-fixes) $ git checkout master\n(master) $ # restore schema to previous state\n(master) $ bin/morphism diff --apply-changes=yes config.yml catalog\n```\n\n## Testing\n\n``` bash\n$ make test\n```\n\n\n## Security\n\nIf you discover any security related issues, please email security@graze.com instead of using the issue tracker.\n\n## Credits\n\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraze%2Fmorphism","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraze%2Fmorphism","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraze%2Fmorphism/lists"}