Getting data into production
Once you have set up your production deployment, you'll need some way to get your products and other data into the system.
The main tasks will be:
- Creation of the database schema
- Importing initial data like roles, tax rates, countries etc.
- Importing catalog data like products, variants, options, facets
- Importing other data used by your application
Creating the initial database schema
The recommended way to create the schema for a new production deployment is to generate an initial migration locally against an empty database. This migration will contain the full database schema for your current Vendure configuration, and can then be committed to source control and run in production in the same way as all later schema changes.
To create the initial migration:
- Point your local Vendure config at an empty database of the same type as production.
- Keep
dbConnectionOptions.synchronizeset tofalse. - Generate an initial migration:
- Review the generated migration file and commit it to source control.
- Run pending migrations in production as part of your deployment process:
If your server entry point already calls runMigrations(config) before bootstrap(config), the committed initial migration will be applied automatically when the server starts.
Using synchronize for the first run
Another possible way to create the schema for a brand-new, empty database is to temporarily enable TypeORM's synchronize feature for the first run. This is simpler, but an initial migration is preferable because it makes the production schema reproducible and auditable.
If you use this approach, enable synchronize with an explicit boolean environment variable:
Set the DB_SYNCHRONIZE variable to true on first start, and then after the schema is created, set it to false or remove it. Do not pass the raw environment variable directly to synchronize, because environment variables are strings and the string "false" is still truthy.
For ongoing schema changes, always use migrations rather than synchronize.
Importing initial & catalog data
Importing initial and catalog data can be handled by Vendure populate() helper function - see the Importing Product Data guide.
Importing other data
Any kinds of data not covered by the populate() function can be imported using a custom script, which can use any Vendure service or service defined by your custom plugins to populate data in any way you like. See the Stand-alone scripts guide.