Skip to content

Commit 696d1e1

Browse files
committed
feat: reallow +180 for longitudes in the database but still normalize others
1 parent e83a64d commit 696d1e1

5 files changed

Lines changed: 1299 additions & 4 deletions

File tree

app/lib/location.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
* @param lat Latitude
66
*/
77
export const validLngLat = (lng: number, lat: number): boolean => {
8-
// the value range for lat is [-90, 90] and for longitude [-180, 180)
9-
return lat >= -90 && lat <= 90 && lng >= -180 && lng < 180
8+
// the value range for lat is [-90, 90] and for longitude [-180, 180]
9+
return lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180
1010
}

app/schema/location.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ export const location = pgTable(
2525
index('location_index').using('gist', t.location),
2626
unique().on(t.location),
2727
sql`CONSTRAINT check_location CHECK (
28-
ST_X(${t.location}) >= -180 AND
29-
ST_X(${t.location}) < 180 AND
28+
ST_X(${t.location}) BETWEEN -180 AND 180
3029
ST_Y(${t.location}) BETWEEN -90 AND 90
3130
)`,
3231
],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- Custom SQL migration file, put your code below! --
2+
ALTER TABLE location
3+
DROP CONSTRAINT check_location;
4+
5+
ALTER TABLE location
6+
ADD CONSTRAINT check_location CHECK (
7+
ST_X(location) BETWEEN -180 AND 180
8+
AND
9+
ST_Y(location) BETWEEN -90 AND 90
10+
);-- Custom SQL migration file, put your code below! --

0 commit comments

Comments
 (0)