Skip to content

Commit 6a75845

Browse files
committed
refactor(location): cleanup
1 parent 897c7c0 commit 6a75845

7 files changed

Lines changed: 44 additions & 34 deletions

File tree

src/deploy/function_distance.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
BEGIN;
22

33
CREATE FUNCTION maevsi.distance(
4-
lat1 DOUBLE PRECISION, lon1 DOUBLE PRECISION,
5-
lat2 DOUBLE PRECISION, lon2 DOUBLE PRECISION
4+
lat1 DOUBLE PRECISION,
5+
lon1 DOUBLE PRECISION,
6+
lat2 DOUBLE PRECISION,
7+
lon2 DOUBLE PRECISION
68
) RETURNS DOUBLE PRECISION AS $$
79
DECLARE
810
earthRadius DOUBLE PRECISION;
@@ -29,5 +31,3 @@ COMMENT ON FUNCTION maevsi.distance(DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE P
2931
GRANT EXECUTE ON FUNCTION maevsi.distance(DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION, DOUBLE PRECISION) TO maevsi_account;
3032

3133
COMMIT;
32-
33-

src/deploy/table_account_private.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ CREATE TABLE maevsi_private.account (
99
email_address_verification UUID DEFAULT gen_random_uuid(),
1010
email_address_verification_valid_until TIMESTAMP,
1111
last_activity TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
location_id UUID REFERENCES maevsi.location(id),
1213
password_hash TEXT NOT NULL,
1314
password_reset_verification UUID,
1415
password_reset_verification_valid_until TIMESTAMP,
15-
upload_quota_bytes BIGINT NOT NULL DEFAULT 10485760, -- 10 mebibyte
16-
location_id UUID REFERENCES maevsi.location(id)
16+
upload_quota_bytes BIGINT NOT NULL DEFAULT 10485760 -- 10 mebibyte
1717
);
1818

1919
COMMENT ON TABLE maevsi_private.account IS 'Private account data.';
@@ -24,11 +24,11 @@ COMMENT ON COLUMN maevsi_private.account.email_address IS 'The account''s email
2424
COMMENT ON COLUMN maevsi_private.account.email_address_verification IS 'The UUID used to verify an email address, or null if already verified.';
2525
COMMENT ON COLUMN maevsi_private.account.email_address_verification_valid_until IS 'The timestamp until which an email address verification is valid.';
2626
COMMENT ON COLUMN maevsi_private.account.last_activity IS 'Timestamp at which the account last requested an access token.';
27+
COMMENT ON COLUMN maevsi_private.account.location_id IS 'Reference to the account''s location data.';
2728
COMMENT ON COLUMN maevsi_private.account.password_hash IS 'The account''s password, hashed and salted.';
2829
COMMENT ON COLUMN maevsi_private.account.password_reset_verification IS 'The UUID used to reset a password, or null if there is no pending reset request.';
2930
COMMENT ON COLUMN maevsi_private.account.password_reset_verification_valid_until IS 'The timestamp until which a password reset is valid.';
3031
COMMENT ON COLUMN maevsi_private.account.upload_quota_bytes IS 'The account''s upload quota in bytes.';
31-
COMMENT ON COLUMN maevsi_private.account.location_id IS 'Reference to the account''s location data.';
3232

3333
CREATE FUNCTION maevsi_private.account_email_address_verification_valid_until() RETURNS TRIGGER AS $$
3434
BEGIN

src/deploy/table_event.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ CREATE TABLE maevsi.event (
1212
is_in_person BOOLEAN,
1313
is_remote BOOLEAN,
1414
location TEXT CHECK (char_length("location") > 0 AND char_length("location") < 300),
15+
location_id UUID REFERENCES maevsi.location(id),
1516
name TEXT NOT NULL CHECK (char_length("name") > 0 AND char_length("name") < 100),
1617
slug TEXT NOT NULL CHECK (char_length(slug) < 100 AND slug ~ '^[-A-Za-z0-9]+$'),
1718
start TIMESTAMP WITH TIME ZONE NOT NULL,
1819
url TEXT CHECK (char_length("url") < 300 AND "url" ~ '^https:\/\/'),
1920
visibility maevsi.event_visibility NOT NULL,
20-
location_id UUID REFERENCES maevsi.location(id),
2121

2222
UNIQUE (author_account_id, slug)
2323
);
@@ -33,12 +33,12 @@ COMMENT ON COLUMN maevsi.event.is_archived IS 'Indicates whether the event is ar
3333
COMMENT ON COLUMN maevsi.event.is_in_person IS 'Indicates whether the event takes place in person.';
3434
COMMENT ON COLUMN maevsi.event.is_remote IS 'Indicates whether the event takes place remotely.';
3535
COMMENT ON COLUMN maevsi.event.location IS 'The event''s location as it can be shown on a map.';
36+
COMMENT ON COLUMN maevsi.event.location_id IS 'Reference to the event''s location data.';
3637
COMMENT ON COLUMN maevsi.event.name IS 'The event''s name.';
3738
COMMENT ON COLUMN maevsi.event.slug IS 'The event''s name, slugified.';
3839
COMMENT ON COLUMN maevsi.event.start IS 'The event''s start date and time, with timezone.';
3940
COMMENT ON COLUMN maevsi.event.url IS 'The event''s unified resource locator.';
4041
COMMENT ON COLUMN maevsi.event.visibility IS 'The event''s visibility.';
41-
COMMENT ON COLUMN maevsi_private.account.location_id IS 'Reference to the event''s location data.';
4242

4343
-- GRANTs, RLS and POLICYs are specified in 'table_event_policy`.
4444

src/deploy/table_location.sql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
BEGIN;
22

33
CREATE TABLE maevsi.location (
4-
id UUID PRIMARY KEY,
4+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
5+
56
location_type CHAR(1) NOT NULL,
6-
latitude DOUBLE PRECISION NOT NULL,
7-
longitude DOUBLE PRECISION NOT NULL,
8-
-- possible future extension (using PostGIS):
9-
-- geom GEOMETRY
7+
latitude DOUBLE PRECISION NOT NULL,
8+
longitude DOUBLE PRECISION NOT NULL,
9+
10+
-- -- possible future extension using PostGIS
11+
-- geom GEOMETRY
1012

1113
CHECK (location_type IN ('A', 'E'))
1214
);
1315

1416
COMMENT ON TABLE maevsi.location IS 'Location data based on GPS coordnates.';
15-
COMMENT ON COLUMN maevsi.location.id IS 'The locations''s internal id.';
17+
COMMENT ON COLUMN maevsi.location.id IS E'@omit create,update\nThe locations''s internal id.';
1618
COMMENT ON COLUMN maevsi.location.location_type IS 'The type of the location (A = account, E = event)';
17-
COMMENT ON COLUMN maevsi.location.latitude IS 'reference to an account (if not null).';
18-
COMMENT ON COLUMN maevsi.location.longitude IS 'reference to an account (if not null).';
19+
COMMENT ON COLUMN maevsi.location.latitude IS 'The coordinate''s latitude.';
20+
COMMENT ON COLUMN maevsi.location.longitude IS 'The coordinate''s longitude.';
1921

2022
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE maevsi.location TO maevsi_account;
2123
GRANT SELECT ON TABLE maevsi.location TO maevsi_anonymous;

src/verify/table_account_private.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ SELECT id,
77
email_address_verification,
88
email_address_verification_valid_until,
99
last_activity,
10+
location_id,
1011
password_hash,
1112
password_reset_verification,
1213
password_reset_verification_valid_until,
13-
upload_quota_bytes,
14-
location_id
14+
upload_quota_bytes
1515
FROM maevsi_private.account WHERE FALSE;
1616

1717
DO $$

src/verify/table_event.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ SELECT id,
1010
is_in_person,
1111
is_remote,
1212
location,
13+
location_id,
1314
name,
1415
slug,
1516
start,
1617
url,
17-
visibility,
18-
location_id
18+
visibility
1919
FROM maevsi.event WHERE FALSE;
2020

2121
ROLLBACK;

test/schema/schema.definition.sql

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,12 @@ CREATE TABLE maevsi.event (
776776
is_in_person boolean,
777777
is_remote boolean,
778778
location text,
779+
location_id uuid,
779780
name text NOT NULL,
780781
slug text NOT NULL,
781782
start timestamp with time zone NOT NULL,
782783
url text,
783784
visibility maevsi.event_visibility NOT NULL,
784-
location_id uuid,
785785
CONSTRAINT event_description_check CHECK (((char_length(description) > 0) AND (char_length(description) < 1000000))),
786786
CONSTRAINT event_invitee_count_maximum_check CHECK ((invitee_count_maximum > 0)),
787787
CONSTRAINT event_location_check CHECK (((char_length(location) > 0) AND (char_length(location) < 300))),
@@ -872,6 +872,13 @@ COMMENT ON COLUMN maevsi.event.is_remote IS 'Indicates whether the event takes p
872872
COMMENT ON COLUMN maevsi.event.location IS 'The event''s location as it can be shown on a map.';
873873

874874

875+
--
876+
-- Name: COLUMN event.location_id; Type: COMMENT; Schema: maevsi; Owner: postgres
877+
--
878+
879+
COMMENT ON COLUMN maevsi.event.location_id IS 'Reference to the event''s location data.';
880+
881+
875882
--
876883
-- Name: COLUMN event.name; Type: COMMENT; Schema: maevsi; Owner: postgres
877884
--
@@ -3113,7 +3120,7 @@ COMMENT ON COLUMN maevsi.legal_term_acceptance.legal_term_id IS 'The ID of the l
31133120
--
31143121

31153122
CREATE TABLE maevsi.location (
3116-
id uuid NOT NULL,
3123+
id uuid DEFAULT gen_random_uuid() NOT NULL,
31173124
location_type character(1) NOT NULL,
31183125
latitude double precision NOT NULL,
31193126
longitude double precision NOT NULL,
@@ -3134,7 +3141,8 @@ COMMENT ON TABLE maevsi.location IS 'Location data based on GPS coordnates.';
31343141
-- Name: COLUMN location.id; Type: COMMENT; Schema: maevsi; Owner: postgres
31353142
--
31363143

3137-
COMMENT ON COLUMN maevsi.location.id IS 'The locations''s internal id.';
3144+
COMMENT ON COLUMN maevsi.location.id IS '@omit create,update
3145+
The locations''s internal id.';
31383146

31393147

31403148
--
@@ -3148,14 +3156,14 @@ COMMENT ON COLUMN maevsi.location.location_type IS 'The type of the location (A
31483156
-- Name: COLUMN location.latitude; Type: COMMENT; Schema: maevsi; Owner: postgres
31493157
--
31503158

3151-
COMMENT ON COLUMN maevsi.location.latitude IS 'reference to an account (if not null).';
3159+
COMMENT ON COLUMN maevsi.location.latitude IS 'The coordinate''s latitude.';
31523160

31533161

31543162
--
31553163
-- Name: COLUMN location.longitude; Type: COMMENT; Schema: maevsi; Owner: postgres
31563164
--
31573165

3158-
COMMENT ON COLUMN maevsi.location.longitude IS 'reference to an account (if not null).';
3166+
COMMENT ON COLUMN maevsi.location.longitude IS 'The coordinate''s longitude.';
31593167

31603168

31613169
--
@@ -3304,11 +3312,11 @@ CREATE TABLE maevsi_private.account (
33043312
email_address_verification uuid DEFAULT gen_random_uuid(),
33053313
email_address_verification_valid_until timestamp without time zone,
33063314
last_activity timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
3315+
location_id uuid,
33073316
password_hash text NOT NULL,
33083317
password_reset_verification uuid,
33093318
password_reset_verification_valid_until timestamp without time zone,
33103319
upload_quota_bytes bigint DEFAULT 10485760 NOT NULL,
3311-
location_id uuid,
33123320
CONSTRAINT account_email_address_check CHECK ((char_length(email_address) < 255))
33133321
);
33143322

@@ -3371,6 +3379,13 @@ COMMENT ON COLUMN maevsi_private.account.email_address_verification_valid_until
33713379
COMMENT ON COLUMN maevsi_private.account.last_activity IS 'Timestamp at which the account last requested an access token.';
33723380

33733381

3382+
--
3383+
-- Name: COLUMN account.location_id; Type: COMMENT; Schema: maevsi_private; Owner: postgres
3384+
--
3385+
3386+
COMMENT ON COLUMN maevsi_private.account.location_id IS 'Reference to the account''s location data.';
3387+
3388+
33743389
--
33753390
-- Name: COLUMN account.password_hash; Type: COMMENT; Schema: maevsi_private; Owner: postgres
33763391
--
@@ -3399,13 +3414,6 @@ COMMENT ON COLUMN maevsi_private.account.password_reset_verification_valid_until
33993414
COMMENT ON COLUMN maevsi_private.account.upload_quota_bytes IS 'The account''s upload quota in bytes.';
34003415

34013416

3402-
--
3403-
-- Name: COLUMN account.location_id; Type: COMMENT; Schema: maevsi_private; Owner: postgres
3404-
--
3405-
3406-
COMMENT ON COLUMN maevsi_private.account.location_id IS 'Reference to the event''s location data.';
3407-
3408-
34093417
--
34103418
-- Name: achievement_code; Type: TABLE; Schema: maevsi_private; Owner: postgres
34113419
--

0 commit comments

Comments
 (0)