-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some fixes in example for ts with node
- Loading branch information
1 parent
522ef57
commit 4b2fe5e
Showing
9 changed files
with
1,176 additions
and
1,679 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
FROM node:10 | ||
FROM node:12 | ||
|
||
WORKDIR /app/ | ||
|
||
COPY . . | ||
|
||
RUN yarn | ||
|
||
CMD yarn synchronize && yarn start | ||
CMD yarn sync-db synchronize && yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,104 @@ | ||
# Node MSSQL Example (JavaScript) | ||
# Node MSSQL Example with TypeScript Migrations | ||
|
||
Sample project for Microsoft SQL Server. | ||
Sample project for sync-db using MSSQL and migrations written in TypeScript. | ||
|
||
## Setup | ||
|
||
Install dependencies. | ||
|
||
```bash | ||
$ yarn | ||
``` | ||
|
||
Configure database connection(s) in the `connections.sync-db.json`. | ||
|
||
```bash | ||
$ cp connections.sync-db.json.example connections.sync-db.json | ||
``` | ||
## Overview | ||
|
||
## Running | ||
This `sync-db` example does a few things in order: | ||
|
||
**Synchronization** | ||
- Prunes database objects inside of [src/sql](src/sql) from the specified database connection(s) if it exists. | ||
- Executes knex database migrations inside of [src/migrations](src/migrations) directory written in TypeScript. | ||
- Creates database objects inside of [src/sql](src/sql) directory using `sync-db`. These database objects are created in the order specified in [sync-db.yml](sync-db.yml). | ||
- Executes a [node script](src/index.js) to check if the synchronized objects can be executed and prints the result. | ||
|
||
Run `synchronize` to run migrations and synchronize all database objects (views, functions, procedures, schemas, etc) in the configured database(s). | ||
|
||
``` | ||
$ yarn synchronize | ||
``` | ||
|
||
``` | ||
Synchronizing... | ||
▸ testdb1 | ||
[✓] Synchronization - started | ||
[✓] Synchronization - pruned (0.02s) | ||
[✓] Migrations - 2 run (0.03s) | ||
- 20191124213750_create_users_table | ||
- 20191124213800_create_tasks_table | ||
[✓] Synchronization - completed (0.15s) | ||
▸ testdb2 | ||
[✓] Synchronization - started | ||
[✓] Synchronization - pruned (0.01s) | ||
[✓] Migrations - 2 run (0.02s) | ||
- 20191124213750_create_users_table | ||
- 20191124213800_create_tasks_table | ||
[✓] Synchronization - completed (0.13s) | ||
Synchronization complete for 2 / 2 connection(s). (0.51s) | ||
``` | ||
|
||
**Running Sample App** | ||
|
||
Run the sample node app. | ||
|
||
``` | ||
$ yarn start | ||
``` | ||
|
||
**Output** | ||
|
||
``` | ||
List of users: | ||
[ 'user1@example.com', | ||
'user2@example.com', | ||
'user3@example.com', | ||
'user4@example.com' ] | ||
List of completed tasks: | ||
[ { id: 21, | ||
user_id: 1, | ||
title: 'Task 1', | ||
description: 'This is task 1.', | ||
is_complete: true, | ||
created_at: null, | ||
updated_at: null }, | ||
{ id: 27, | ||
user_id: 2, | ||
title: 'Task 7', | ||
description: 'This is task 7.', | ||
is_complete: true, | ||
created_at: null, | ||
updated_at: null }, | ||
{ id: 30, | ||
user_id: 2, | ||
title: 'Task 10', | ||
description: 'This is task 10.', | ||
is_complete: true, | ||
created_at: null, | ||
updated_at: null }, | ||
{ id: 35, | ||
user_id: 3, | ||
title: 'Task 15', | ||
description: 'This is task 15.', | ||
is_complete: true, | ||
created_at: null, | ||
updated_at: null } ] | ||
Calculations: | ||
{ 'Sum of 6 and 7': 13, | ||
'Product of 6 and 7': 42, | ||
'Square of 6': 36 } | ||
Current date time: 2020-04-25T19:02:38.320Z | ||
``` | ||
## Setup | ||
|
||
## Docker | ||
Setup will require [docker](https://docs.docker.com/engine/) and [docker-compose](https://docs.docker.com/compose/gettingstarted/). | ||
|
||
Set `DB_PASSWORD` (password for `SA` user) in environment. e.g. | ||
Configure database connection(s) in `connections.sync-db.json` by copying `connections.sync-db.json.example`. For ease of use, the example app will work without making any changes to `connections.sync-db.json`. Throwaway database credentials have been set in [docker-compose.yml](docker-compose.yml). | ||
|
||
```bash | ||
$ export DB_PASSWORD=Password@123 | ||
$ cp connections.sync-db.json.example connections.sync-db.json | ||
``` | ||
|
||
Configure database connection(s) in the `connections.sync-db.json`. Use same `password` as `DB_PASSWORD` | ||
Note: `host` has to be the service name of docker container for `mssql`. | ||
## Run | ||
|
||
Run the docker-compose services in order. | ||
|
||
```bash | ||
$ cp connections.sync-db.json.docker connections.sync-db.json | ||
$ docker-compose up -d db | ||
$ docker-compose up app | ||
``` | ||
|
||
Then run (in order). | ||
## Output | ||
|
||
```bash | ||
$ docker-compose up -d mssql | ||
$ docker-compose up app | ||
example-app | yarn run v1.22.5 | ||
example-app | $ /app/node_modules/.bin/sync-db synchronize | ||
example-app | Synchronizing... | ||
example-app | | ||
example-app | ▸ testdb1 | ||
example-app | [✓] Synchronization - started | ||
example-app | [✓] Synchronization - pruned (0.05s) | ||
example-app | [✓] Migrations - up to date (0.06s) | ||
example-app | [✓] Synchronization - completed (0.23s) | ||
example-app | | ||
example-app | Synchronization complete for 1 / 1 connection(s). (1.07s) | ||
example-app | | ||
example-app | Done in 1.99s. | ||
example-app | yarn run v1.22.5 | ||
example-app | $ node src/index.js | ||
example-app | | ||
example-app | List of users: | ||
example-app | [ | ||
example-app | 'user1@example.com', | ||
example-app | 'user2@example.com', | ||
example-app | 'user3@example.com', | ||
example-app | 'user4@example.com' | ||
example-app | ] | ||
example-app | | ||
example-app | List of completed tasks: | ||
example-app | [ | ||
example-app | { | ||
example-app | id: 21, | ||
example-app | title: 'Task 1', | ||
example-app | user_id: 1, | ||
example-app | description: 'This is task 1.', | ||
example-app | is_complete: true, | ||
example-app | created_at: 2021-03-22T09:06:27.906Z, | ||
example-app | updated_at: 2021-03-22T09:06:27.906Z | ||
example-app | }, | ||
example-app | { | ||
example-app | id: 27, | ||
example-app | title: 'Task 7', | ||
example-app | user_id: 2, | ||
example-app | description: 'This is task 7.', | ||
example-app | is_complete: true, | ||
example-app | created_at: 2021-03-22T09:06:27.906Z, | ||
example-app | updated_at: 2021-03-22T09:06:27.906Z | ||
example-app | }, | ||
example-app | { | ||
example-app | id: 30, | ||
example-app | title: 'Task 10', | ||
example-app | user_id: 2, | ||
example-app | description: 'This is task 10.', | ||
example-app | is_complete: true, | ||
example-app | created_at: 2021-03-22T09:06:27.906Z, | ||
example-app | updated_at: 2021-03-22T09:06:27.906Z | ||
example-app | }, | ||
example-app | { | ||
example-app | id: 35, | ||
example-app | title: 'Task 15', | ||
example-app | user_id: 3, | ||
example-app | description: 'This is task 15.', | ||
example-app | is_complete: true, | ||
example-app | created_at: 2021-03-22T09:06:27.906Z, | ||
example-app | updated_at: 2021-03-22T09:06:27.906Z | ||
example-app | } | ||
example-app | ] | ||
example-app | | ||
example-app | Calculations: | ||
example-app | { 'Sum of 6 and 7': 13, 'Square of 6': 36, 'Product of 6 and 7': 42 } | ||
example-app | | ||
example-app | Current date time: 2021-03-22T09:06:28.930Z | ||
example-app exited with code 0 | ||
``` |
15 changes: 0 additions & 15 deletions
15
examples/node-app-mssql-ts/connections.sync-db.json.docker
This file was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
examples/node-app-mssql-ts/connections.sync-db.json.example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.