Skip to content

Commit 95fd8bf

Browse files
committed
Update table columns
1 parent bf1c318 commit 95fd8bf

File tree

7 files changed

+26
-35
lines changed

7 files changed

+26
-35
lines changed

gateway-ha/src/main/java/io/trino/gateway/ha/DatabaseAuditLogger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public DatabaseAuditLogger(Jdbi jdbi)
3737
public void logAudit(String user, String ip, String backendName, AuditAction action, AuditContext context, boolean success, String userComment)
3838
{
3939
try {
40-
dao.log(user, ip, backendName, action.toString(), context.toString(), success ? 1 : 0,
40+
dao.log(user, ip, backendName, action.toString(), context.toString(), success,
4141
AuditLogger.sanitizeComment(userComment), Timestamp.from(Instant.now()));
4242
}
4343
catch (Exception e) {

gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/AuditLogDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public interface AuditLogDao
2222
{
2323
@SqlUpdate("""
2424
INSERT INTO gateway_audit_logs (user_name, ip_address, backend_name, operation, context, success, user_comment, change_time)
25-
VALUES (:user_name, :ip_address, :backend_name, :operation, :context, :success, :user_comment, :change_time)
25+
VALUES (:user_name, :ip_address, :backend_name, :operation, :context, :success, LEFT(:user_comment, 1024), :change_time)
2626
""")
2727
void log(@Bind("user_name") String user_name,
2828
@Bind("ip_address") String ip_address,
2929
@Bind("backend_name") String backend_name,
3030
@Bind("operation") String operation,
3131
@Bind("context") String context,
32-
@Bind("success") int success,
32+
@Bind("success") Boolean success,
3333
@Bind("user_comment") String user_comment,
3434
@Bind("change_time") Timestamp change_time);
3535
}

gateway-ha/src/main/resources/gateway-ha-persistence-mysql.sql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ CREATE TABLE IF NOT EXISTS exact_match_source_selectors (
7878
);
7979

8080
CREATE TABLE IF NOT EXISTS gateway_audit_logs (
81-
audit_id BIGINT NOT NULL AUTO_INCREMENT,
81+
audit_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
8282
user_name VARCHAR(256) NOT NULL,
8383
ip_address VARCHAR(45),
8484
backend_name VARCHAR(256) NOT NULL,
85-
operation VARCHAR(256) NOT NULL,
86-
context VARCHAR(256) NOT NULL,
85+
operation VARCHAR(64) NOT NULL,
86+
context VARCHAR(64) NOT NULL,
8787
success BOOLEAN NOT NULL,
8888
user_comment VARCHAR(1024),
89-
change_time TIMESTAMP NOT NULL,
90-
91-
PRIMARY KEY(audit_id)
89+
change_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
9290
);

gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ CREATE TABLE IF NOT EXISTS exact_match_source_selectors (
7878
);
7979

8080
CREATE TABLE IF NOT EXISTS gateway_audit_logs (
81-
audit_id BIGSERIAL,
81+
audit_id BIGSERIAL PRIMARY KEY,
8282
user_name VARCHAR(256) NOT NULL,
8383
ip_address VARCHAR(45),
8484
backend_name VARCHAR(256) NOT NULL,
85-
operation VARCHAR(256) NOT NULL,
86-
context VARCHAR(256) NOT NULL,
87-
success SMALLINT NOT NULL CHECK (success IN (0, 1)),
85+
operation VARCHAR(64) NOT NULL,
86+
context VARCHAR(64) NOT NULL,
87+
success BOOLEAN NOT NULL,
8888
user_comment VARCHAR(1024),
89-
change_time TIMESTAMP NOT NULL,
90-
91-
PRIMARY KEY(audit_id)
89+
change_time TIMESTAMPTZ NOT NULL DEFAULT now()
9290
);

gateway-ha/src/main/resources/mysql/V1__create_schema.sql

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ CREATE TABLE IF NOT EXISTS exact_match_source_selectors (
7878
);
7979

8080
CREATE TABLE IF NOT EXISTS gateway_audit_logs (
81-
audit_id BIGINT NOT NULL AUTO_INCREMENT,
81+
audit_id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
8282
user_name VARCHAR(256) NOT NULL,
8383
ip_address VARCHAR(45),
8484
backend_name VARCHAR(256) NOT NULL,
85-
operation VARCHAR(256) NOT NULL,
86-
context VARCHAR(256) NOT NULL,
85+
operation VARCHAR(64) NOT NULL,
86+
context VARCHAR(64) NOT NULL,
8787
success BOOLEAN NOT NULL,
8888
user_comment VARCHAR(1024),
89-
change_time TIMESTAMP NOT NULL,
90-
91-
PRIMARY KEY(audit_id)
89+
change_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
9290
);

gateway-ha/src/main/resources/oracle/V1__create_schema.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ CREATE TABLE exact_match_source_selectors(
6969
);
7070

7171
CREATE TABLE gateway_audit_logs (
72-
audit_id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
72+
audit_id NUMBER(19) GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
7373
user_name VARCHAR(256) NOT NULL,
7474
ip_address VARCHAR2(45),
7575
backend_name VARCHAR(256) NOT NULL,
76-
operation VARCHAR(256) NOT NULL,
77-
context VARCHAR(256) NOT NULL,
78-
success NUMBER(1) NOT NULL CHECK (success IN (0,1)),
76+
operation VARCHAR(64) NOT NULL,
77+
context VARCHAR(64) NOT NULL,
78+
success BOOLEAN NOT NULL,
7979
user_comment VARCHAR(1024),
80-
change_time TIMESTAMP NOT NULL,
81-
PRIMARY KEY(audit_id)
80+
change_time TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL
8281
);

gateway-ha/src/main/resources/postgresql/V1__create_schema.sql

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,13 @@ CREATE TABLE IF NOT EXISTS exact_match_source_selectors (
7878
);
7979

8080
CREATE TABLE IF NOT EXISTS gateway_audit_logs (
81-
audit_id BIGSERIAL,
81+
audit_id BIGSERIAL PRIMARY KEY,
8282
user_name VARCHAR(256) NOT NULL,
8383
ip_address VARCHAR(45),
8484
backend_name VARCHAR(256) NOT NULL,
85-
operation VARCHAR(256) NOT NULL,
86-
context VARCHAR(256) NOT NULL,
87-
success SMALLINT NOT NULL CHECK (success IN (0, 1)),
85+
operation VARCHAR(64) NOT NULL,
86+
context VARCHAR(64) NOT NULL,
87+
success BOOLEAN NOT NULL,
8888
user_comment VARCHAR(1024),
89-
change_time TIMESTAMP NOT NULL,
90-
91-
PRIMARY KEY(audit_id)
89+
change_time TIMESTAMPTZ NOT NULL DEFAULT now()
9290
);

0 commit comments

Comments
 (0)