Skip to content

Commit a6cc99b

Browse files
yhabteabjulianbrost
authored andcommitted
schema: Require & use citext extension
1 parent 2b3ca42 commit a6cc99b

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

internal/config/runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ func (r *RuntimeConfig) GetRuleEscalation(escalationID int64) *rule.Escalation {
144144
return nil
145145
}
146146

147-
// GetContact returns *recipient.Contact by the given username.
147+
// GetContact returns *recipient.Contact by the given username (case-insensitive).
148148
// Returns nil when the given username doesn't exist.
149149
func (r *RuntimeConfig) GetContact(username string) *recipient.Contact {
150150
for _, contact := range r.Contacts {
151-
if contact.Username.String == username {
151+
if strings.EqualFold(contact.Username.String, username) {
152152
return contact
153153
}
154154
}

schema/pgsql/schema.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CREATE TABLE available_channel_type (
4040

4141
CREATE TABLE channel (
4242
id bigserial,
43-
name text NOT NULL,
43+
name citext NOT NULL,
4444
type text NOT NULL REFERENCES available_channel_type(type), -- 'email', 'sms', ...
4545
config text, -- JSON with channel-specific attributes
4646
-- for now type determines the implementation, in the future, this will need a reference to a concrete
@@ -51,8 +51,8 @@ CREATE TABLE channel (
5151

5252
CREATE TABLE contact (
5353
id bigserial,
54-
full_name text NOT NULL,
55-
username text, -- reference to web user
54+
full_name citext NOT NULL,
55+
username citext, -- reference to web user
5656
default_channel_id bigint NOT NULL REFERENCES channel(id),
5757
color varchar(7) NOT NULL, -- hex color codes e.g #000000
5858

@@ -72,7 +72,7 @@ CREATE TABLE contact_address (
7272

7373
CREATE TABLE contactgroup (
7474
id bigserial,
75-
name text NOT NULL,
75+
name citext NOT NULL,
7676
color varchar(7) NOT NULL, -- hex color codes e.g #000000
7777

7878
CONSTRAINT pk_contactgroup PRIMARY KEY (id)
@@ -87,7 +87,7 @@ CREATE TABLE contactgroup_member (
8787

8888
CREATE TABLE schedule (
8989
id bigserial,
90-
name text NOT NULL,
90+
name citext NOT NULL,
9191

9292
CONSTRAINT pk_schedule PRIMARY KEY (id)
9393
);
@@ -163,7 +163,7 @@ CREATE TABLE source (
163163
id bigserial,
164164
-- The type "icinga2" is special and requires (at least some of) the icinga2_ prefixed columns.
165165
type text NOT NULL,
166-
name text NOT NULL,
166+
name citext NOT NULL,
167167
-- will likely need a distinguishing value for multiple sources of the same type in the future, like for example
168168
-- the Icinga DB environment ID for Icinga 2 sources
169169

@@ -230,14 +230,14 @@ CREATE TABLE event (
230230
type text NOT NULL,
231231
severity severity,
232232
message text,
233-
username text,
233+
username citext,
234234

235235
CONSTRAINT pk_event PRIMARY KEY (id)
236236
);
237237

238238
CREATE TABLE rule (
239239
id bigserial,
240-
name text NOT NULL,
240+
name citext NOT NULL,
241241
timeperiod_id bigint REFERENCES timeperiod(id),
242242
object_filter text,
243243
is_active boolenum NOT NULL DEFAULT 'y',
@@ -250,7 +250,7 @@ CREATE TABLE rule_escalation (
250250
rule_id bigint NOT NULL REFERENCES rule(id),
251251
position integer NOT NULL,
252252
condition text,
253-
name text, -- if not set, recipients are used as a fallback for display purposes
253+
name citext, -- if not set, recipients are used as a fallback for display purposes
254254
fallback_for bigint REFERENCES rule_escalation(id),
255255

256256
CONSTRAINT pk_rule_escalation PRIMARY KEY (id),

schema/pgsql/upgrades/027.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE EXTENSION IF NOT EXISTS citext;
2+
3+
ALTER TABLE contact
4+
ALTER COLUMN full_name TYPE citext,
5+
ALTER COLUMN username TYPE citext;
6+
7+
ALTER TABLE contactgroup ALTER COLUMN name TYPE citext;
8+
ALTER TABLE schedule ALTER COLUMN name TYPE citext;
9+
ALTER TABLE channel ALTER COLUMN name TYPE citext;
10+
ALTER TABLE source ALTER COLUMN name TYPE citext;
11+
ALTER TABLE event ALTER COLUMN username TYPE citext;
12+
ALTER TABLE rule ALTER COLUMN name TYPE citext;
13+
ALTER TABLE rule_escalation ALTER COLUMN name TYPE citext;

0 commit comments

Comments
 (0)