This package may ultimately contain a data model for use in the new Loconomics backend. For now, it contains utilities to regenerate our schema, as well as a conversion using typeorm-model-generator with post-processing done via TSLint.
yarn install
or npm install
from within the clone../regenerate-all.sh
to drop and recreate the database and load the schema.mssql://sa:Password!!11@localhost:1433/loconomics
.regenerate-all.sh contains commented-out code to regenerate the TypeORM schema, but we shouldn't need to do that anymore. If something in the generated schema is broken, we should instead modify the files directly unless something is significantly broken in the initial generation.
Only schema files under the /schema
folders must be edited.
The root file schema.sql
is autogenerated by a tool (a Nodejs script on this repo), by running yarn build-schema-sql
.
Tables DDLs are created following a set of important rules, so the full database schema created didn't fail:
GO
) before the CREATE TABLE
statementCREATE TABLE
statement contains columns, primary keys and only constraints that don't depend on other objects (like default values)ALTER TABLE
statement, that goes after the first batch separator (GO
)That ensure we can create a full schema.sql
without dependency problems between tables.
Running the typeorm-model-generator
or the yarn start
using the correct connection settings and the SQLServer up, still connectivity errors may appear, which seems to be usual when using named instances rather than default instance, but still some steps may apply on this last case so keep reading.
next errors may appear , Port for SQLEXPRESS not found in localhost
(where SQLEXPRESS is the instance name). This problems happened using named instances, some steps may not apply when using a default instance.
Example error messages: Error connecting to MSSQL Server
, ESOCKET
, EINSTLOOKUP / getaddrinfo ENOTFOUND
, Port for _instanceName_ not found in localhost
localhost\SQLEXPRESS
, you should set-up localhost\\SQLEXPRESS
typeorm-model-generator
..env
file for yarn start
, is not needed, may even fail because of double slash there.Example error message: Failed to connect to _host_ in 15000ms
.
SQL Server Browser
.This applies to named instances and using Git Bash on Windows (it's a powerfull option since you get a Linux terminal experience, but there are edge bugs).
After set the environment variable, or including it in-line with the command yarn install
, a connection error is throwed. The process sends to output the value of the env var, double check it's the correct one; you should check that the back slash was converted to forward slash without warning, that's the source of the problem. I don't know why to prevent that automatic conversion (the ideal step) but there is a workaround:
.env
file at the root directory to set-up connection settings, that applies even if other set-up files exists like ormconfig.js
so does not conflict with that..env
file at the project root directory with your connection settings using the recognized names.
.gitignore
but double check is not committed.yarn start
again to test it.