seed automates the database tasks that are done repeatedly and frequently to remove production and test server variables from SQL dump files and replaces them with local environment variables.
Command bin/seed path/to/file_name.sql --profile www.example.com --delete-file
The command above will do the following:
- Copies the file
path/to/file_name.sql
tocode/var/db/file_name.sql
- Reads the configurations in
code/var/profiles/www.example.com/env.php
to set up tasks - Performs find and replace using sed commands on the SQL file.
- Imports The SQL file into the seed container.
- Runs DDL commands
- Insert new data
- Update existing data
- Delete data
- Truncate tables
- Drop Tables
- Runs
mysqldump
command as the final step resulting a new SQL dump file insidecode/var/db/seed-{database_name}-{timestamp}.sql
- If the option
--delete-file
was provided, it will delete the copied SQL filecode/var/db/file_name.sql
bin/seed build
bin/seed composer install
bin/seed test
Note
seed used and tested on macOS only. You are free to try it on windows or linux and contribute if there are problems.
- Clone the repo
git@github.com:alaa-almaliki/seed.git
- Go into seed folder -
cd seed
- Build the container
bin/seed build
- Run composer
bin/seed composer install
- Optionally set the path of seed script
bin/seed set:path
so you can access the script from anywhereseed profiles create --name www.example.com
- Defaults are set in
.env
file - MariaDB is the only available option currently
SQL_SERVER=mariadb
- Versions (10.4, 10.6 and 10.11) are available currently
MARIADB_VERSION=10.11
- Bind port is set to
MYSQL_PORT=3307
, you can change it however you like. - Rebuild the seed container after changing these variables
After building the seed container, you can do the following:
- Run
bin/seed profiles create --name www.example.com
- This will create
code/var/profiles/www.example.com/env.php
file - Configure
env.php
file as you wish- Section
mysql
is the MySQL database credentials and options you wish to create inside the seed container - Section
mysqldump
will be the settings related the database export in the final step - Section
sed
is the find and replace settings, it will be performed on SQL file before the import - Section
ddl
has the following settings:insert
will insert new rows to a given tableupdate
will update existing rows in a given tabledelete
will delete rows from a given tabletruncate
will truncate tablesdrop
will drop tables
- Section
After setting up profiles, you can run seed as follows:
- Run
bin/seed path/to/file_name.sql --profile www.example.com --delete-file
- Wait for the script to finish
- Once done, the file
code/var/db/seed-{database_name}-{timestamp}.sql
will be available for you to use
The command bin/seed profiles
has the following:
bin/seed profiles create --name [profile-name]
will create a profile with a given namebin/seed profiles delete --name [profile-name]
will delete a profilebin/seed profiles copy --source [profile-name-1] --target [profile-name-2]
will duplicate/copy a profilebin/seed profiles list
will list profiles
Updating seed can be done by the command bin/seed update
Command | Summary |
---|---|
bin/seed update |
Update seed based on the current branch |
bin/seed profiles action [create,copy,delete,list] |
Runs profiles actions as create, delete, copy and list |
bin/seed seed path/to/file.sql --profile {www.example.com} [--delete-file] |
Runs seed, to clean up your local database file is required profile is required delete-file will delete the original SQL file if provided |
bin/seed test |
Runs tests |
bin/seed build [--no-cache] |
Builds the container, optionally with arguments |
bin/seed composer {install} |
Runs composer inside the container |
bin/seed rebuild |
Rebuilds the container from scratch, it will remove the volume which will cause loss in data |
bin/seed up |
Starts the container |
bin/seed stop |
Stops the container |
bin/seed restart |
Restarts the container |
bin/seed destroy |
Destroys the container |
bin/seed chown |
Fixes filesystem ownership |
bin/seed ssh |
Access into the container |
bin/seed mysql |
Access mysql interactive shell |
bin/seed copy_to_container {folder_name} |
Copy Filesystem from host ./code/ to container /var/www/html |
bin/seed copy_from_container {folder_name} |
Copy Filesystem from container /var/www/html to host ./code/ |
bin/seed set:path |
Sets the bin path in .zshrc, so you can use seed from anywhere in the terminal. Then you can do like seed build --no-cache |
All contributions are welcome.