loconomics / loconomics-data

0 stars 2 forks source link

@loconomics/data

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.

How to Help

  1. Clone this repository.
  2. Run yarn install or npm install from within the clone.
  3. Launch an instance of SQLServer somehow. This guide assumes you're using the Dockerized new backend but any instance will do.
  4. Run ./regenerate-all.sh to drop and recreate the database and load the schema.
  5. Set a _DATABASEURL environment variable to something like 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.

Editing the database Schema

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

Tables DDLs are created following a set of important rules, so the full database schema created didn't fail:

That ensure we can create a full schema.sql without dependency problems between tables.

Troubleshooting

Failed connections to database on Windows

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.

Server not found or wrong port errors

Example error messages: Error connecting to MSSQL Server, ESOCKET, EINSTLOOKUP / getaddrinfo ENOTFOUND, Port for _instanceName_ not found in localhost

Failed connection with timeout

Example error message: Failed to connect to _host_ in 15000ms.

Setting up DATABASE_URL didn't work

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: