nerds-and-company/schematic
Craft setup and sync tool
Installs: 6 637
Dependents: 3
Suggesters: 0
Stars: 106
Watchers: 17
Forks: 12
Open Issues: 4
Type:craft-plugin
Requires
- php: ^7.0
- craftcms/cms: ^3.0
- symfony/yaml: ^3.0 || ^4.0
Requires (Dev)
- codeception/codeception: ^2.4
- squizlabs/php_codesniffer: ^3.2
- phpmd/phpmd: ^2.6
- dev-master
- 4.0.1
- 4.0.0
- 3.8.8
- 3.8.7
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.1
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.1
- 3.0.0
- 2.0.1
- 2.0.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.4
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- dev-php70-compatibility
- dev-meta
- dev-travis-improvements
README
Schematic allows you to synchronize your Craft setup over multiple environments. It does this by exporting information about assets, database (fields, sections, users), locales and plugins to a YAML file that can be imported in other environments.
Installation
This tool can be installed using Composer. Run the following command from the root of your project:
composer require nerds-and-company/schematic
This will add nerds-and-company/schematic
as a requirement to your project's composer.json
file and install the source-code into the vendor/nerds-and-company/schematic
directory.
Schematic is now available as an installable plugin in Craft. You can install it in the cp or use ./craft install/plugin schematic
Usage
Basic usage
The most common usage pattern of this tool, to synchronize from a development to a production environment, would be:
- Create a Craft project locally
- Set up all of the desired plugins, sections, templates, etc.
- Run a Schematic export locally
- Optionally, if a revision control system is used, commit the schema file to the local repository
- Deploy the Craft application to a production environment
- Run a Schematic import remotely
Or, to synchronize from a production to a development environment:
- Run a Schematic export remotely
- Pull the schema file locally
- Optionally, if a revision control system is used, commit the schema file to the local repository
- Run a Schematic import locally
Exporting
An export can be created by running:
./craft schematic/export
To skip exporting a specific of data type, exclusions can be specified in the following form:
./craft schematic/export --exclude=volumes
Multiple exclusions can also be specified:
./craft schematic/export --exclude=volumes,categoryGroups
The same goes for only exporting a subset of data types:
./craft schematic/export --include=volumes,categoryGroups
See [Supported DataTypes](#Supported DataTypes)
An export will generate a schema file at config/schema.yml
. The file path can be changed using the --file
flag, for instance craft schematic/export --file=path/to/my-schema.yml
Importing
To run an import with schematic, a schema file needs to be present. An import can be created by running:
./craft schematic/import
By default schematic will look at config/schema.yml
. To change the path where schematic will look for the schema file, use the --file
flag.
Optionally the --force
flag can be used to make the import delete any items which are not mentioned in the import file.
WARNING!! This will also delete any related content.
To skip importing a specific of data type, exclusions can be specified in the following form:
./craft schematic/import --exclude=volumes
Multiple exclusions can also be specified:
./craft schematic/import --exclude=volumes,categoryGroups
Keys in the schema file can be overridden by passing an override file to schematic using the --override_file
flag, for instance: vendor/bin/schematic import --override_file=craft/config/override.yml
.
See [Supported DataTypes](#Supported DataTypes)
Supported DataTypes
Here is a list of all of the data types and their corresponding exclude parameter values:
Data Type | Exclude/Include Parameter |
---|---|
plugins | plugins |
Sites | sites |
Asset Transforms | assetTransforms |
Category Groups | categoryGroups |
Element Indexes | elementIndexSettings |
Fields | fields |
Global Sets | globalSets |
Plugins | plugins |
Sections | sections |
Tag Groups | tagGroups |
UserSettings | userSettings |
User Groups | userGroups |
Volumes | volumes |
Overrides
Specific keys can be overriden by adding a key in craft/config/override.yml
and setting the corresponding environment variable. The key name in the override.yml
needs to be the same as the key you want to override from schema.yml
, including any parent key names. The value has to start and end with a %
(percentage sign). The correspending environment value will be SCHEMATIC_{value_without_percentage_signs}
.
Example
If the following override.yml
is defined:
parent: key_name: %key_value%
Then the environment variable SCHEMATIC_KEY_VALUE
needs to be set. The value of this environment variable will override the key key_name
. If the environment variable is not set Schematic will throw an error.
Hooks
There are no hooks available at this time.
Caveats
Schematic uses handles to identify content. When a handle is changed in the schema file and import is run with force a new content type will be created with that handle, and the old content type will be deleted!
It is recommended to change content type handles with craft content migrations and to run these migration before running a schematic import.
License
This project has been licensed under the MIT License (MIT). Please see License File for more information.
Changelog
Credits
Inspired and based on the awesome ArtVandelay Plugin and built by these awesome individuals