agrs-sequelize-sdk 1.0.17 → 1.0.18
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/LICENSE +21 -21
- package/README.md +179 -179
- package/config/config.json +24 -24
- package/index.js +75 -75
- package/models/ActivityHistory.js +72 -72
- package/models/Ad.js +144 -144
- package/models/AdAccount.js +99 -99
- package/models/AdCreative.js +61 -61
- package/models/AdPerformance.js +65 -65
- package/models/AdPerformanceHourly.js +51 -51
- package/models/AdSet.js +72 -72
- package/models/Campaign.js +116 -116
- package/models/CodefuelCampaign.js +113 -113
- package/models/CodefuelCampaignKWHistory.js +41 -41
- package/models/CodefuelKeywords.js +35 -35
- package/models/CurrencyRate.js +27 -27
- package/models/Files.js +64 -64
- package/models/Folders.js +133 -133
- package/models/KeywordPerformance.js +65 -65
- package/models/KeywordRotationState.js +51 -46
- package/models/Rule.js +38 -38
- package/models/TonicCampaign.js +97 -97
- package/models/Users.js +38 -38
- package/models/pixel.js +32 -32
- package/models/pixels.js +32 -32
- package/package.json +19 -21
- package/run.ps1 +98 -98
- package/run.sh +85 -85
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Agressive Scale LTD
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Agressive Scale LTD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,179 +1,179 @@
|
|
|
1
|
-
# agrs-sequelize SDK
|
|
2
|
-
|
|
3
|
-
The `agrs-sequelize` SDK provides a structured way to manage your database models using Sequelize ORM. It allows you to easily add, update, and manage models, with support for publishing updates to NPM and pushing changes to GitHub.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Prerequisites](#prerequisites)
|
|
8
|
-
- [Installation](#installation)
|
|
9
|
-
- [Usage](#usage)
|
|
10
|
-
- [Adding or Modifying Models](#adding-or-modifying-models)
|
|
11
|
-
- [Model Loading](#model-loading)
|
|
12
|
-
- [Publishing Changes](#publishing-changes)
|
|
13
|
-
- [Using PowerShell (Windows)](#using-powershell-windows)
|
|
14
|
-
- [Using Bash (Linux/macOS)](#using-bash-linuxmacos)
|
|
15
|
-
- [Script Details](#script-details)
|
|
16
|
-
- [run.ps1 (PowerShell Script for Windows)](#runps1-powershell-script-for-windows)
|
|
17
|
-
- [run.sh (Bash Script for Linux/macOS)](#runsh-bash-script-for-linuxmacos)
|
|
18
|
-
- [Example Model File](#example-model-file)
|
|
19
|
-
- [Versioning](#versioning)
|
|
20
|
-
- [Troubleshooting](#troubleshooting)
|
|
21
|
-
- [License](#license)
|
|
22
|
-
|
|
23
|
-
## Prerequisites
|
|
24
|
-
|
|
25
|
-
Ensure the following dependencies are installed on your system:
|
|
26
|
-
|
|
27
|
-
- **Node.js**: [Download Node.js](https://nodejs.org/)
|
|
28
|
-
- **Sequelize**: Used for database interaction.
|
|
29
|
-
- **Git**: Required for version control and publishing changes to GitHub.
|
|
30
|
-
- **npm**: For managing and publishing packages.
|
|
31
|
-
- **PowerShell** (Windows) or **Bash** (Linux/macOS): For running automation scripts.
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
1. **Clone the Repository:**
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
git clone https://github.com/your-repo/agrs-sequelize.git
|
|
39
|
-
cd agrs-sequelize
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
2. **Install Dependencies:**
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
npm install
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# Usage
|
|
50
|
-
|
|
51
|
-
## Adding or Modifying Models
|
|
52
|
-
To add or modify models in the agrs-sequelize SDK:
|
|
53
|
-
|
|
54
|
-
1. **Create or Edit a Model:**
|
|
55
|
-
|
|
56
|
-
- Add a new model file inside the models directory or edit an existing one.
|
|
57
|
-
- Each model file should export a function that initializes the model with Sequelize.
|
|
58
|
-
|
|
59
|
-
```javascript
|
|
60
|
-
// models/YourModel.js
|
|
61
|
-
module.exports = (sequelize, DataTypes) => {
|
|
62
|
-
const YourModel = sequelize.define('YourModel', {
|
|
63
|
-
fieldName: {
|
|
64
|
-
type: DataTypes.STRING,
|
|
65
|
-
allowNull: false,
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Define associations (optional)
|
|
70
|
-
YourModel.associate = (models) => {
|
|
71
|
-
YourModel.hasMany(models.OtherModel);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
return YourModel;
|
|
75
|
-
};
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
2. **Define Associations (if required):**
|
|
79
|
-
|
|
80
|
-
Use the associate method to define relationships with other models.
|
|
81
|
-
Associations like hasMany, belongsTo, etc., are supported.
|
|
82
|
-
### Model Loading
|
|
83
|
-
Models are automatically loaded when initializing Sequelize.
|
|
84
|
-
The index.js file ensures all models in the models directory are properly loaded and associated.
|
|
85
|
-
|
|
86
|
-
## Publishing Changes
|
|
87
|
-
After modifying or adding models, publish the changes to NPM and GitHub.
|
|
88
|
-
|
|
89
|
-
### Using PowerShell (Windows)
|
|
90
|
-
Open PowerShell as Administrator.
|
|
91
|
-
|
|
92
|
-
Run the Script:
|
|
93
|
-
|
|
94
|
-
```powershell
|
|
95
|
-
./run.ps1
|
|
96
|
-
```
|
|
97
|
-
The script will:
|
|
98
|
-
|
|
99
|
-
- Check for jq installation.
|
|
100
|
-
- Bump the version in package.json.
|
|
101
|
-
- Publish to NPM.
|
|
102
|
-
- Commit and push changes to GitHub.
|
|
103
|
-
|
|
104
|
-
### Using Bash (Linux/macOS)
|
|
105
|
-
Open a Bash Terminal.
|
|
106
|
-
|
|
107
|
-
Run the Script:
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
./run.sh
|
|
111
|
-
```
|
|
112
|
-
The script performs the same tasks as the PowerShell script, tailored for Bash environments.
|
|
113
|
-
|
|
114
|
-
## Script Details
|
|
115
|
-
### run.ps1 (PowerShell Script for Windows)
|
|
116
|
-
Automates the publishing process:
|
|
117
|
-
|
|
118
|
-
- Ensures jq is installed.
|
|
119
|
-
- Increments the version in package.json.
|
|
120
|
-
- Publishes the package to NPM.
|
|
121
|
-
- Commits and pushes changes to GitHub.
|
|
122
|
-
|
|
123
|
-
### run.sh (Bash Script for Linux/macOS)
|
|
124
|
-
Provides similar functionality:
|
|
125
|
-
|
|
126
|
-
- Checks for jq installation.
|
|
127
|
-
- Bumps the package version.
|
|
128
|
-
= Publishes to NPM.
|
|
129
|
-
= Commits and pushes to GitHub.
|
|
130
|
-
|
|
131
|
-
## Example Model File
|
|
132
|
-
```javascript
|
|
133
|
-
Copy code
|
|
134
|
-
// models/YourModel.js
|
|
135
|
-
module.exports = (sequelize, DataTypes) => {
|
|
136
|
-
const YourModel = sequelize.define('YourModel', {
|
|
137
|
-
name: {
|
|
138
|
-
type: DataTypes.STRING,
|
|
139
|
-
allowNull: false,
|
|
140
|
-
},
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
// Define associations (optional)
|
|
144
|
-
YourModel.associate = (models) => {
|
|
145
|
-
YourModel.hasMany(models.OtherModel);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
return YourModel;
|
|
149
|
-
};
|
|
150
|
-
```
|
|
151
|
-
In this example:
|
|
152
|
-
|
|
153
|
-
YourModel has a name field.
|
|
154
|
-
It has a hasMany association with OtherModel.
|
|
155
|
-
## Versioning
|
|
156
|
-
Versioning is handled automatically:
|
|
157
|
-
|
|
158
|
-
- The scripts increment the version in package.json.
|
|
159
|
-
- Follows semantic versioning (major, minor, patch).
|
|
160
|
-
- Updated versions are published to NPM and committed to the repository.
|
|
161
|
-
|
|
162
|
-
## Troubleshooting
|
|
163
|
-
- ### Permission Issues:
|
|
164
|
-
|
|
165
|
-
- Linux/macOS: Ensure scripts have execute permissions (chmod +x run.sh).
|
|
166
|
-
- ### NPM Login Errors:
|
|
167
|
-
|
|
168
|
-
- The script will prompt for NPM login if not already logged in.
|
|
169
|
-
- Verify NPM account credentials.
|
|
170
|
-
|
|
171
|
-
- ### Missing Dependencies:
|
|
172
|
-
|
|
173
|
-
- The script checks for jq and installs it if missing.
|
|
174
|
-
## License
|
|
175
|
-
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1
|
+
# agrs-sequelize SDK
|
|
2
|
+
|
|
3
|
+
The `agrs-sequelize` SDK provides a structured way to manage your database models using Sequelize ORM. It allows you to easily add, update, and manage models, with support for publishing updates to NPM and pushing changes to GitHub.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Prerequisites](#prerequisites)
|
|
8
|
+
- [Installation](#installation)
|
|
9
|
+
- [Usage](#usage)
|
|
10
|
+
- [Adding or Modifying Models](#adding-or-modifying-models)
|
|
11
|
+
- [Model Loading](#model-loading)
|
|
12
|
+
- [Publishing Changes](#publishing-changes)
|
|
13
|
+
- [Using PowerShell (Windows)](#using-powershell-windows)
|
|
14
|
+
- [Using Bash (Linux/macOS)](#using-bash-linuxmacos)
|
|
15
|
+
- [Script Details](#script-details)
|
|
16
|
+
- [run.ps1 (PowerShell Script for Windows)](#runps1-powershell-script-for-windows)
|
|
17
|
+
- [run.sh (Bash Script for Linux/macOS)](#runsh-bash-script-for-linuxmacos)
|
|
18
|
+
- [Example Model File](#example-model-file)
|
|
19
|
+
- [Versioning](#versioning)
|
|
20
|
+
- [Troubleshooting](#troubleshooting)
|
|
21
|
+
- [License](#license)
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
|
|
25
|
+
Ensure the following dependencies are installed on your system:
|
|
26
|
+
|
|
27
|
+
- **Node.js**: [Download Node.js](https://nodejs.org/)
|
|
28
|
+
- **Sequelize**: Used for database interaction.
|
|
29
|
+
- **Git**: Required for version control and publishing changes to GitHub.
|
|
30
|
+
- **npm**: For managing and publishing packages.
|
|
31
|
+
- **PowerShell** (Windows) or **Bash** (Linux/macOS): For running automation scripts.
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
1. **Clone the Repository:**
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
git clone https://github.com/your-repo/agrs-sequelize.git
|
|
39
|
+
cd agrs-sequelize
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2. **Install Dependencies:**
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# Usage
|
|
50
|
+
|
|
51
|
+
## Adding or Modifying Models
|
|
52
|
+
To add or modify models in the agrs-sequelize SDK:
|
|
53
|
+
|
|
54
|
+
1. **Create or Edit a Model:**
|
|
55
|
+
|
|
56
|
+
- Add a new model file inside the models directory or edit an existing one.
|
|
57
|
+
- Each model file should export a function that initializes the model with Sequelize.
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
// models/YourModel.js
|
|
61
|
+
module.exports = (sequelize, DataTypes) => {
|
|
62
|
+
const YourModel = sequelize.define('YourModel', {
|
|
63
|
+
fieldName: {
|
|
64
|
+
type: DataTypes.STRING,
|
|
65
|
+
allowNull: false,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Define associations (optional)
|
|
70
|
+
YourModel.associate = (models) => {
|
|
71
|
+
YourModel.hasMany(models.OtherModel);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return YourModel;
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. **Define Associations (if required):**
|
|
79
|
+
|
|
80
|
+
Use the associate method to define relationships with other models.
|
|
81
|
+
Associations like hasMany, belongsTo, etc., are supported.
|
|
82
|
+
### Model Loading
|
|
83
|
+
Models are automatically loaded when initializing Sequelize.
|
|
84
|
+
The index.js file ensures all models in the models directory are properly loaded and associated.
|
|
85
|
+
|
|
86
|
+
## Publishing Changes
|
|
87
|
+
After modifying or adding models, publish the changes to NPM and GitHub.
|
|
88
|
+
|
|
89
|
+
### Using PowerShell (Windows)
|
|
90
|
+
Open PowerShell as Administrator.
|
|
91
|
+
|
|
92
|
+
Run the Script:
|
|
93
|
+
|
|
94
|
+
```powershell
|
|
95
|
+
./run.ps1
|
|
96
|
+
```
|
|
97
|
+
The script will:
|
|
98
|
+
|
|
99
|
+
- Check for jq installation.
|
|
100
|
+
- Bump the version in package.json.
|
|
101
|
+
- Publish to NPM.
|
|
102
|
+
- Commit and push changes to GitHub.
|
|
103
|
+
|
|
104
|
+
### Using Bash (Linux/macOS)
|
|
105
|
+
Open a Bash Terminal.
|
|
106
|
+
|
|
107
|
+
Run the Script:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
./run.sh
|
|
111
|
+
```
|
|
112
|
+
The script performs the same tasks as the PowerShell script, tailored for Bash environments.
|
|
113
|
+
|
|
114
|
+
## Script Details
|
|
115
|
+
### run.ps1 (PowerShell Script for Windows)
|
|
116
|
+
Automates the publishing process:
|
|
117
|
+
|
|
118
|
+
- Ensures jq is installed.
|
|
119
|
+
- Increments the version in package.json.
|
|
120
|
+
- Publishes the package to NPM.
|
|
121
|
+
- Commits and pushes changes to GitHub.
|
|
122
|
+
|
|
123
|
+
### run.sh (Bash Script for Linux/macOS)
|
|
124
|
+
Provides similar functionality:
|
|
125
|
+
|
|
126
|
+
- Checks for jq installation.
|
|
127
|
+
- Bumps the package version.
|
|
128
|
+
= Publishes to NPM.
|
|
129
|
+
= Commits and pushes to GitHub.
|
|
130
|
+
|
|
131
|
+
## Example Model File
|
|
132
|
+
```javascript
|
|
133
|
+
Copy code
|
|
134
|
+
// models/YourModel.js
|
|
135
|
+
module.exports = (sequelize, DataTypes) => {
|
|
136
|
+
const YourModel = sequelize.define('YourModel', {
|
|
137
|
+
name: {
|
|
138
|
+
type: DataTypes.STRING,
|
|
139
|
+
allowNull: false,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Define associations (optional)
|
|
144
|
+
YourModel.associate = (models) => {
|
|
145
|
+
YourModel.hasMany(models.OtherModel);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return YourModel;
|
|
149
|
+
};
|
|
150
|
+
```
|
|
151
|
+
In this example:
|
|
152
|
+
|
|
153
|
+
YourModel has a name field.
|
|
154
|
+
It has a hasMany association with OtherModel.
|
|
155
|
+
## Versioning
|
|
156
|
+
Versioning is handled automatically:
|
|
157
|
+
|
|
158
|
+
- The scripts increment the version in package.json.
|
|
159
|
+
- Follows semantic versioning (major, minor, patch).
|
|
160
|
+
- Updated versions are published to NPM and committed to the repository.
|
|
161
|
+
|
|
162
|
+
## Troubleshooting
|
|
163
|
+
- ### Permission Issues:
|
|
164
|
+
|
|
165
|
+
- Linux/macOS: Ensure scripts have execute permissions (chmod +x run.sh).
|
|
166
|
+
- ### NPM Login Errors:
|
|
167
|
+
|
|
168
|
+
- The script will prompt for NPM login if not already logged in.
|
|
169
|
+
- Verify NPM account credentials.
|
|
170
|
+
|
|
171
|
+
- ### Missing Dependencies:
|
|
172
|
+
|
|
173
|
+
- The script checks for jq and installs it if missing.
|
|
174
|
+
## License
|
|
175
|
+
This project is licensed under the MIT License. See the LICENSE file for details.
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
package/config/config.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"development": {
|
|
3
|
-
"username": "postgres",
|
|
4
|
-
"password": "1234",
|
|
5
|
-
"database": "dev-db",
|
|
6
|
-
"host": "localhost",
|
|
7
|
-
"port": 5432,
|
|
8
|
-
"dialect": "postgres"
|
|
9
|
-
},
|
|
10
|
-
"test": {
|
|
11
|
-
"username": "root",
|
|
12
|
-
"password": "1234",
|
|
13
|
-
"database": "test-db",
|
|
14
|
-
"host": "127:0.0.1",
|
|
15
|
-
"dialect": "postgres"
|
|
16
|
-
},
|
|
17
|
-
"production": {
|
|
18
|
-
"username": "root",
|
|
19
|
-
"password": "1234",
|
|
20
|
-
"database": "prod-db",
|
|
21
|
-
"host": "127:0.0.1",
|
|
22
|
-
"dialect": "postgres"
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"development": {
|
|
3
|
+
"username": "postgres",
|
|
4
|
+
"password": "1234",
|
|
5
|
+
"database": "dev-db",
|
|
6
|
+
"host": "localhost",
|
|
7
|
+
"port": 5432,
|
|
8
|
+
"dialect": "postgres"
|
|
9
|
+
},
|
|
10
|
+
"test": {
|
|
11
|
+
"username": "root",
|
|
12
|
+
"password": "1234",
|
|
13
|
+
"database": "test-db",
|
|
14
|
+
"host": "127:0.0.1",
|
|
15
|
+
"dialect": "postgres"
|
|
16
|
+
},
|
|
17
|
+
"production": {
|
|
18
|
+
"username": "root",
|
|
19
|
+
"password": "1234",
|
|
20
|
+
"database": "prod-db",
|
|
21
|
+
"host": "127:0.0.1",
|
|
22
|
+
"dialect": "postgres"
|
|
23
|
+
}
|
|
24
|
+
}
|
package/index.js
CHANGED
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
const Sequelize = require("sequelize");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
|
|
5
|
-
// const env = process.env.NODE_ENV || "development";
|
|
6
|
-
class DBModels {
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.config = config;
|
|
9
|
-
this.db = {};
|
|
10
|
-
|
|
11
|
-
// Initialize Sequelize
|
|
12
|
-
const sequelize = new Sequelize(
|
|
13
|
-
this.config.database,
|
|
14
|
-
this.config.username,
|
|
15
|
-
this.config.password,
|
|
16
|
-
{
|
|
17
|
-
host: this.config.host,
|
|
18
|
-
dialect: this.config.dialect,
|
|
19
|
-
port: this.config.port,
|
|
20
|
-
logging: false,
|
|
21
|
-
dialectOptions: {
|
|
22
|
-
ssl: {
|
|
23
|
-
require: true, // Require SSL
|
|
24
|
-
rejectUnauthorized: false, // For self-signed or unverified certificates
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
pool: {
|
|
28
|
-
max: 100,
|
|
29
|
-
min: 0,
|
|
30
|
-
acquire: 30000,
|
|
31
|
-
idle: 10000,
|
|
32
|
-
},
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// // Initialize PaperTrail
|
|
37
|
-
// const PaperTrail = require("sequelize-paper-trail").init(sequelize, {
|
|
38
|
-
// userModel: false, // Optional: set this to true if you have a user model to track who made the changes
|
|
39
|
-
// enableRevisionChangeModel: true, // Optional: set this to true if you want to store the changes made to each revision
|
|
40
|
-
// });
|
|
41
|
-
// PaperTrail.defineModels(); // Define the Revision and RevisionChange models
|
|
42
|
-
|
|
43
|
-
// Load all models
|
|
44
|
-
fs.readdirSync(path.join(__dirname, "models"))
|
|
45
|
-
.filter((file) => {
|
|
46
|
-
return file.indexOf(".") !== 0 && file.slice(-3) === ".js";
|
|
47
|
-
})
|
|
48
|
-
.forEach((file) => {
|
|
49
|
-
const model = require(path.join(__dirname, "models", file))(
|
|
50
|
-
sequelize,
|
|
51
|
-
Sequelize.DataTypes
|
|
52
|
-
);
|
|
53
|
-
this.db[model.name] = model;
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Apply PaperTrail to CodefuelCampaign model
|
|
57
|
-
// const CodefuelCampaign = db["CodefuelCampaign"];
|
|
58
|
-
// if (CodefuelCampaign) {
|
|
59
|
-
// CodefuelCampaign.Revisions = CodefuelCampaign.hasPaperTrail();
|
|
60
|
-
// }
|
|
61
|
-
|
|
62
|
-
// Set up associations
|
|
63
|
-
Object.keys(this.db).forEach((modelName) => {
|
|
64
|
-
if (this.db[modelName].associate) {
|
|
65
|
-
this.db[modelName].associate(this.db);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// Export the db object with Sequelize and models
|
|
70
|
-
this.db.sequelize = sequelize;
|
|
71
|
-
this.db.Sequelize = Sequelize;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = DBModels;
|
|
1
|
+
const Sequelize = require("sequelize");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
// const env = process.env.NODE_ENV || "development";
|
|
6
|
+
class DBModels {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
this.db = {};
|
|
10
|
+
|
|
11
|
+
// Initialize Sequelize
|
|
12
|
+
const sequelize = new Sequelize(
|
|
13
|
+
this.config.database,
|
|
14
|
+
this.config.username,
|
|
15
|
+
this.config.password,
|
|
16
|
+
{
|
|
17
|
+
host: this.config.host,
|
|
18
|
+
dialect: this.config.dialect,
|
|
19
|
+
port: this.config.port,
|
|
20
|
+
logging: false,
|
|
21
|
+
dialectOptions: {
|
|
22
|
+
ssl: {
|
|
23
|
+
require: true, // Require SSL
|
|
24
|
+
rejectUnauthorized: false, // For self-signed or unverified certificates
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
pool: {
|
|
28
|
+
max: 100,
|
|
29
|
+
min: 0,
|
|
30
|
+
acquire: 30000,
|
|
31
|
+
idle: 10000,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// // Initialize PaperTrail
|
|
37
|
+
// const PaperTrail = require("sequelize-paper-trail").init(sequelize, {
|
|
38
|
+
// userModel: false, // Optional: set this to true if you have a user model to track who made the changes
|
|
39
|
+
// enableRevisionChangeModel: true, // Optional: set this to true if you want to store the changes made to each revision
|
|
40
|
+
// });
|
|
41
|
+
// PaperTrail.defineModels(); // Define the Revision and RevisionChange models
|
|
42
|
+
|
|
43
|
+
// Load all models
|
|
44
|
+
fs.readdirSync(path.join(__dirname, "models"))
|
|
45
|
+
.filter((file) => {
|
|
46
|
+
return file.indexOf(".") !== 0 && file.slice(-3) === ".js";
|
|
47
|
+
})
|
|
48
|
+
.forEach((file) => {
|
|
49
|
+
const model = require(path.join(__dirname, "models", file))(
|
|
50
|
+
sequelize,
|
|
51
|
+
Sequelize.DataTypes
|
|
52
|
+
);
|
|
53
|
+
this.db[model.name] = model;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Apply PaperTrail to CodefuelCampaign model
|
|
57
|
+
// const CodefuelCampaign = db["CodefuelCampaign"];
|
|
58
|
+
// if (CodefuelCampaign) {
|
|
59
|
+
// CodefuelCampaign.Revisions = CodefuelCampaign.hasPaperTrail();
|
|
60
|
+
// }
|
|
61
|
+
|
|
62
|
+
// Set up associations
|
|
63
|
+
Object.keys(this.db).forEach((modelName) => {
|
|
64
|
+
if (this.db[modelName].associate) {
|
|
65
|
+
this.db[modelName].associate(this.db);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Export the db object with Sequelize and models
|
|
70
|
+
this.db.sequelize = sequelize;
|
|
71
|
+
this.db.Sequelize = Sequelize;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = DBModels;
|