Skip to content

Commit 3c4dbd8

Browse files
authored
Merge pull request #186 from sarojrana/feature/trigger
Add support for triggers
2 parents d653471 + 497da3e commit 3c4dbd8

File tree

10 files changed

+42
-7
lines changed

10 files changed

+42
-7
lines changed

.travis.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
language: node_js
22

3+
dist: jammy
4+
35
branches:
46
only:
57
- master
68

79
node_js:
810
- node
11+
- 18
912
- 16
10-
- 14
1113

1214
git:
1315
depth: false
1416

1517
install:
1618
# Install hub
17-
- sudo snap install hub --classic
19+
- sudo apt update
20+
- sudo apt install hub
1821
- hub --version
1922

20-
# Install github-changelog-generator.
23+
# Install github-changelog-generator
2124
- gem install github_changelog_generator
2225

23-
# install dependencies
26+
# Install dependencies
2427
- yarn
2528

2629
before_script:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TRIGGER dbo.trg_users
2+
ON dbo.users
3+
FOR DELETE
4+
AS
5+
BEGIN
6+
DECLARE @deleted_record_count INT = (SELECT COUNT(*) FROM deleted);
7+
8+
PRINT CAST(@deleted_record_count AS VARCHAR(500)) + ' user records deleted.';
9+
END;

examples/node-app-mssql-ts/sync-db.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sql:
44
# Create objects in dbo schema
55
- function/dbo/sum.sql
66
- function/dbo/square.sql
7+
- trigger/dbo/trg_users.sql
78

89
# Create objects in utils schema
910
- schema/utils.sql
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TRIGGER dbo.trg_users
2+
ON dbo.users
3+
FOR DELETE
4+
AS
5+
BEGIN
6+
DECLARE @deleted_record_count INT = (SELECT COUNT(*) FROM deleted);
7+
8+
PRINT CAST(@deleted_record_count AS VARCHAR(500)) + ' user records deleted.';
9+
END;

examples/node-app-mssql/sync-db.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sql:
44
# Create objects in dbo schema
55
- function/dbo/sum.sql
66
- function/dbo/square.sql
7+
- trigger/dbo/trg_users.sql
78

89
# Create objects in utils schema
910
- schema/utils.sql
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TRIGGER dbo.trg_users
2+
ON dbo.users
3+
FOR DELETE
4+
AS
5+
BEGIN
6+
DECLARE @deleted_record_count INT = (SELECT COUNT(*) FROM deleted);
7+
8+
PRINT CAST(@deleted_record_count AS VARCHAR(500)) + ' user records deleted.';
9+
END;

examples/node-mssql-programmatic-use/sync-db.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ sql:
44
# Create objects in dbo schema
55
- function/dbo/sum.sql
66
- function/dbo/square.sql
7+
- trigger/dbo/trg_users.sql
78

89
# Create objects in utils schema
910
- schema/utils.sql

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@leapfrogtechnology/sync-db",
33
"description": "Command line utility to synchronize and version control relational database objects across databases",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"license": "MIT",
66
"main": "lib/index.js",
77
"types": "lib/index.d.ts",

src/enum/DatabaseObjectTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ enum DatabaseObjectTypes {
55
VIEW = 'view',
66
SCHEMA = 'schema',
77
FUNCTION = 'function',
8-
PROCEDURE = 'procedure'
8+
PROCEDURE = 'procedure',
9+
TRIGGER = 'trigger'
910
}
1011

1112
export default DatabaseObjectTypes;

src/service/sqlRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const dropStatementsMap: Mapping<string> = {
1717
[DatabaseObjectTypes.SCHEMA]: 'DROP SCHEMA IF EXISTS',
1818
[DatabaseObjectTypes.VIEW]: 'DROP VIEW IF EXISTS',
1919
[DatabaseObjectTypes.FUNCTION]: 'DROP FUNCTION IF EXISTS',
20-
[DatabaseObjectTypes.PROCEDURE]: 'DROP PROCEDURE IF EXISTS'
20+
[DatabaseObjectTypes.PROCEDURE]: 'DROP PROCEDURE IF EXISTS',
21+
[DatabaseObjectTypes.TRIGGER]: 'DROP TRIGGER IF EXISTS'
2122
};
2223

2324
/**

0 commit comments

Comments
 (0)