Build adonis migrations, factories and models with pre-configured relationships from Database Schema.
Based on a schema-builder for laravel and using the same schema format as schema-builder.
This package works with AdonisJS v4. In your project directory you'll need ace, fold and cli installed:
npm install --save @adonisjs/ace @adonisjs/cli @adonisjs/fold
These are all peer dependencies so you will get a warning from NPM if they're not installed first. Then install adonis-schema-builder:
npm install --save adonis-schema-builder
Add the following to your aceProviders
array in start/app.js
:
'adonis-schema-builder/providers/BuilderProvider'
You should now see the schema:build
option when running adonis
or ace
.
Use the schema-builder GUI to design your schema, and export as JSON. All of the table and column options in the schema builder are supported, although some column types might be substituted to supported Knex types.
Run adonis schema:build <path to schema file>
in your project root to import the schema file and generate source files. You will be asked to confirm before overwriting any existing files.
- A create table migration for each table.
- A model for each table (except link tables) including validator and sanitisation rules and relationships.
- A factory js file, with a blueprint for each model.
- Link tables - link tables (tables that exist only to join other models) must be denoted with an underscore (i.e. posts_categories).
- Soft Deletes - Currently not supported in V4, but should be added soon.
- Validator message - Messages corresponding to validator rules
- Seeds - use the factories to create a seed file that creates entities that follow the relationship rules.
- Tests - generate integration tests to check that models and factories are set up correctly and are compatible with adonis-lucid.