agrs-sequelize-sdk 1.0.5 → 1.0.6

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.
Files changed (3) hide show
  1. package/README.md +179 -1
  2. package/package.json +1 -1
  3. package/run.bat +0 -105
package/README.md CHANGED
@@ -1 +1,179 @@
1
- # agrs-sequelize
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/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"agrs-sequelize-sdk","version":"1.0.5","main":"index.js","scripts":{"start":"node index.js","sync":"node services/sequelizeService.js","test":"echo \"Error: no test specified\" \u0026\u0026 exit 1"},"keywords":[],"author":"","license":"ISC","description":"","dependencies":{"pg":"^8.13.0","pg-hstore":"^2.3.4","sequelize":"^6.37.4"}}
1
+ {"name":"agrs-sequelize-sdk","version":"1.0.6","main":"index.js","scripts":{"start":"node index.js","sync":"node services/sequelizeService.js","test":"echo \"Error: no test specified\" \u0026\u0026 exit 1"},"keywords":[],"author":"","license":"ISC","description":"","dependencies":{"pg":"^8.13.0","pg-hstore":"^2.3.4","sequelize":"^6.37.4"}}
package/run.bat DELETED
@@ -1,105 +0,0 @@
1
- @echo off
2
- setlocal
3
-
4
- :: Check if running as administrator
5
- net session >nul 2>&1
6
- if %ERRORLEVEL% neq 0 (
7
- echo This script must be run as an administrator.
8
- echo Please right-click on the script and select 'Run as Administrator'.
9
- pause
10
- exit /b 1
11
- )
12
-
13
- :: Check if jq is installed
14
- where jq >nul 2>nul
15
- if %ERRORLEVEL% neq 0 (
16
- echo jq not found. Downloading jq manually...
17
- powershell -Command "Invoke-WebRequest -Uri https://github.com/stedolan/jq/releases/download/jq-1.6/jq-win64.exe -OutFile %TEMP%\jq.exe"
18
- if exist %TEMP%\jq.exe (
19
- move /y %TEMP%\jq.exe %SystemRoot%\System32\jq.exe >nul
20
- if %ERRORLEVEL% neq 0 (
21
- echo Failed to move jq to System32. Please run this script as administrator.
22
- exit /b 1
23
- )
24
- echo jq installed manually.
25
- ) else (
26
- echo Failed to download jq. Please install it manually.
27
- exit /b 1
28
- )
29
- )
30
-
31
- :: Step 1: Check if already logged in to NPM
32
- npm whoami >nul 2>nul
33
- if %ERRORLEVEL% neq 0 (
34
- echo Not logged in. Logging in to NPM...
35
- npm login
36
- if %ERRORLEVEL% neq 0 (
37
- echo NPM login failed. Exiting...
38
- exit /b 1
39
- )
40
- ) else (
41
- for /f %%i in ('npm whoami') do set USERNAME=%%i
42
- echo Already logged in to NPM as %USERNAME%
43
- )
44
-
45
- :: Step 2: Increment version in package.json
46
- for /f "tokens=*" %%i in ('jq -r ".version" package.json') do set current_version=%%i
47
-
48
- if "%current_version%"=="" (
49
- echo Could not find version in package.json
50
- exit /b 1
51
- )
52
-
53
- :: Split version into major, minor, patch
54
- for /f "tokens=1-3 delims=." %%a in ("%current_version%") do (
55
- set major=%%a
56
- set minor=%%b
57
- set patch=%%c
58
- )
59
-
60
- :: Increment version numbers with three-digit logic
61
- if "%patch%"=="99" (
62
- set patch=0
63
- if "%minor%"=="99" (
64
- set minor=0
65
- set /a major+=1
66
- ) else (
67
- set /a minor+=1
68
- )
69
- ) else (
70
- set /a patch+=1
71
- )
72
-
73
- set new_version=%major%.%minor%.%patch%
74
-
75
- :: Update the version in package.json using jq
76
- jq --arg new_version "%new_version%" ".version = $new_version" package.json > temp.json && move /y temp.json package.json
77
-
78
- if %ERRORLEVEL% neq 0 (
79
- echo Failed to update package.json. Exiting...
80
- exit /b 1
81
- )
82
-
83
- echo Version updated from %current_version% to %new_version%
84
-
85
- :: Step 3: Publish the package to NPM
86
- npm publish
87
- if %ERRORLEVEL% neq 0 (
88
- echo NPM publish failed. Exiting...
89
- exit /b 1
90
- )
91
-
92
- :: Step 4: Commit the changes and push to GitHub
93
- git add .
94
- git commit -m "Bump version to %new_version%"
95
- git push origin %cd:~2,100%
96
-
97
- if %ERRORLEVEL% neq 0 (
98
- echo Failed to push changes to GitHub. Exiting...
99
- exit /b 1
100
- )
101
-
102
- echo Version %new_version% published and changes pushed to GitHub successfully!
103
-
104
- endlocal
105
- exit /b 0