Skip to content

Commit

Permalink
Add SQL lint
Browse files Browse the repository at this point in the history
  • Loading branch information
louisroyer committed Jul 10, 2024
1 parent 2be92aa commit 9284753
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ jobs:
run: go get .
- name: Build
run: go build -v ./...
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install depends
run: sudo apt-get install -qy make && pip install sqlfluff
- name: Run SQL lint
run: make lint
11 changes: 11 additions & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[sqlfluff]
dialect = postgres
max_line_length = 140

[sqlfluff:rules]
# old configuration, to be compatible with Debian stable
max_line_length = 140
indent_unit = tab

[sqlfluff:indentation]
indent_unit = tab
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ uninstall:
$(RM) $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6
$(RM) $(DESTDIR)$(IPROUTE2_RTPROTOS_D)/nextmn.conf
$(RM) $(DESTDIR)$(IPROUTE2_RTTABLES_D)/nextmn.conf
lint:
sqlfluff lint
15 changes: 12 additions & 3 deletions internal/database/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ CREATE TABLE IF NOT EXISTS uplink_gtp4 (
srgw_ip INET,
gnb_ip INET,
action_uuid UUID NOT NULL,
PRIMARY KEY(uplink_teid, srgw_ip, gnb_ip)
PRIMARY KEY (uplink_teid, srgw_ip, gnb_ip)
);

CREATE TABLE IF NOT EXISTS rule (
uuid UUID PRIMARY KEY,
type_uplink BOOL NOT NULL,
Expand All @@ -14,13 +15,21 @@ CREATE TABLE IF NOT EXISTS rule (
match_ue_ip_prefix CIDR NOT NULL,
match_gnb_ip_prefix CIDR
);
CREATE OR REPLACE PROCEDURE insert_uplink_rule(IN uuid UUID, IN enabled BOOL, IN ue_ip_prefix CIDR, IN gnb_ip_prefix CIDR, IN next_hop INET, IN srh INET ARRAY)

CREATE OR REPLACE PROCEDURE insert_uplink_rule(
IN uuid UUID, IN enabled BOOL, IN ue_ip_prefix CIDR,
IN gnb_ip_prefix CIDR, IN next_hop INET, IN srh INET ARRAY
)
LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO rule(uuid, type_uplink, enabled, match_ue_ip_prefix, match_gnb_ip_prefix, action_next_hop, action_srh)
VALUES(uuid, TRUE, enabled, ue_ip_prefix, gnb_ip_prefix, next_hop, srh);
END;$$;
CREATE OR REPLACE PROCEDURE insert_downlink_rule(IN uuid UUID, IN enabled BOOL, IN ue_ip_prefix CIDR, IN next_hop INET, IN srh INET ARRAY)

CREATE OR REPLACE PROCEDURE insert_downlink_rule(
IN uuid UUID, IN enabled BOOL, IN ue_ip_prefix CIDR,
IN next_hop INET, IN srh INET ARRAY
)
LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO rule(uuid, type_uplink, enabled, match_ue_ip_prefix, action_next_hop, action_srh)
Expand Down

0 comments on commit 9284753

Please sign in to comment.