minimonolith 0.13.6 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +4 -0
- package/README.md +17 -0
- package/package.json +1 -1
- package/src/database/databaseService.js +8 -5
- package/src/model/loadModels.js +1 -1
package/.env.example
ADDED
package/README.md
CHANGED
|
@@ -131,3 +131,20 @@ export default (MODELS, ROUTE_CODE) => ({
|
|
|
131
131
|
.superRefine(DB_VALIDATION.exists(MODELS.todo, 'id')),
|
|
132
132
|
})
|
|
133
133
|
```
|
|
134
|
+
|
|
135
|
+
## Database Authentication
|
|
136
|
+
|
|
137
|
+
To set up authentication for the database, you need to provide the necessary environment variables in a `.env` file. Here's an example of a `.env` file for connecting to a MySQL database at 0.0.0.0:
|
|
138
|
+
|
|
139
|
+
```makefile
|
|
140
|
+
MM_API_DB_USERNAME=<your_database_username>
|
|
141
|
+
MM_API_DB_PASSWORD=<your_database_password>
|
|
142
|
+
MM_API_DB_DATABASE=<your_database_name>
|
|
143
|
+
MM_API_DB_HOST=0.0.0.0
|
|
144
|
+
MM_API_DB_PORT=<your_database_port>
|
|
145
|
+
MM_API_DB_DIALECT=mysql
|
|
146
|
+
MM_API_LOCAL_ENV=true
|
|
147
|
+
MM_API_PROD_ENV=false
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Make sure to replace the placeholders with your actual database credentials. The `MM_API_LOCAL_ENV` variable is used to allow Sequelize to alter table structure automatically when working locally, while the `MM_API_PROD_ENV` variable controls logging of secret credentials for debugging purposes in non-production environments.
|
package/package.json
CHANGED
|
@@ -27,11 +27,14 @@ const establishConnection = async ORM => {
|
|
|
27
27
|
|
|
28
28
|
const registerDatabaseService = async API => {
|
|
29
29
|
try {
|
|
30
|
-
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
const { MM_API_DB_DIALECT, MM_API_DB_DB, MM_API_DB_USER,
|
|
31
|
+
MM_API_DB_PASS, MM_API_DB_HOST, MM_API_DB_PORT, MM_API_DB_STORAGE } = process.env;
|
|
32
|
+
const SEQUELIZE_OPTIONS = { dialect: MM_API_DB_DIALECT, host: MM_API_DB_HOST,
|
|
33
|
+
port: MM_API_DB_PORT, storage: MM_API_DB_STORAGE, logging: false };
|
|
34
|
+
|
|
35
|
+
if (!process.env.PROD_ENV) console.log({ ROUTE_CODE, MM_API_DB_VARS: { MM_API_DB_DIALECT,
|
|
36
|
+
MM_API_DB_USER, MM_API_DB_PASS, MM_API_DB_HOST, MM_API_DB_PORT, MM_API_DB_DB, MM_API_DB_STORAGE }});
|
|
37
|
+
API.ORM = new Sequelize(MM_API_DB_DB, MM_API_DB_USER, MM_API_DB_PASS, SEQUELIZE_OPTIONS);
|
|
35
38
|
establishConnection(API.ORM);
|
|
36
39
|
|
|
37
40
|
} catch (DB_ERROR) { console.error({ ROUTE_CODE, DB_ERROR }); }
|
package/src/model/loadModels.js
CHANGED
|
@@ -19,7 +19,7 @@ const loadAndSyncModels = async API => {
|
|
|
19
19
|
Object.entries(MODELS).forEach(([serviceName, model]) => { model.associate(MODELS); });
|
|
20
20
|
|
|
21
21
|
console.log({ ROUTE_CODE, SYNCING_ORM: 'SYNCING_ORM' });
|
|
22
|
-
await API.ORM.sync({ alter: process.env.
|
|
22
|
+
await API.ORM.sync({ alter: process.env.MM_API_LOCAL_ENV ? true : false });
|
|
23
23
|
|
|
24
24
|
return MODELS;
|
|
25
25
|
};
|