Deploy, load or build script from model of SQL database
npm install dbmodelIf you want to use this tool from JavaScript interface, please use dbgate-api package.
Model is stored as a collection of files:
* tables - stored as YAML files
* columns
* indexes
* primary keys
* foreign keys
* views - stored as SQL file with extension .view.sql
* stored procedures - stored as SQL file with extension .proc.sql
* functions - stored as SQL file with extension .func.sql
npm install --global dbmodel
npm install --save dbmodel
``shload from existing database
dbmodel load -s localhost -u USERNAME -p PASSWORD -d DATABASE -e mssql@dbgate-plugin-mssql OUTPUT_FOLDER
Parameter -e (or --engine) specifies database dialect and connection driver to be used
Supported databases:
- MySQL -
-e mysql@dbgate-plugin-mysql
- MS SQL Server - -e mssql@dbgate-plugin-mssql
- PostgreSQL - -e postgres@dbgate-plugin-postgres
- SQLite - -e sqlite@dbgate-plugin-sqlite
- Oracle - -e oracle@dbgate-plugin-oracle
- MariaDB - -e mariadb@dbgate-plugin-mysql
- CockroachDB - -e cockroach@dbgate-plugin-postgres
- Amazon Redshift - -e redshift@dbgate-plugin-postgres
Table yaml file documentation
`yaml
name: Album # table name
columns:
- name: AlbumId # column name
type: int # data type. is used directly in target SQL engine
autoIncrement: true # column is autoincrement
notNull: true # column is not nullable (default: is nullable)
- name: Title
type: nvarchar
length: 160 # maximum character length
notNull: true
- name: ArtistId
type: int
references: Artist # name of table. Is used for creating foreign key
- name: isDeleted
type: bit
notNull: true
default: 0 # default value
primaryKey:
- AlbumId # list of primary key column names
indexes:
- name: UQ_AlbumTitleArtistId # index name
unique: true # whether index is unique. default=false
columns: # list of index columns
- Title
- ArtistId
filter: isDeleted=0 # if defined, filtered index (with WHERE condition) is created
continueOnError: true # if true and there was error in creating this index, continue (suitable for lately added unique indexes)
data: # static data (only for list tables)
- AlbumId: -1 # values for all columns, which should be filled
Title: Predefined static album
``