From 95c7b26da0670b5107a4aa8cd8eb5e2ece514dfd Mon Sep 17 00:00:00 2001 From: Jan Schutte <4732389+SchutteJan@users.noreply.github.com> Date: Sun, 14 Jul 2024 12:28:32 +0200 Subject: [PATCH] feat: Add areas table migration --- .../2024-07-14-091228_add-area-table/down.sql | 2 ++ .../2024-07-14-091228_add-area-table/up.sql | 9 +++++++++ backend/src/db/sql_types.rs | 4 ++++ backend/src/schema.rs | 14 ++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 backend/migrations/2024-07-14-091228_add-area-table/down.sql create mode 100644 backend/migrations/2024-07-14-091228_add-area-table/up.sql diff --git a/backend/migrations/2024-07-14-091228_add-area-table/down.sql b/backend/migrations/2024-07-14-091228_add-area-table/down.sql new file mode 100644 index 0000000..e9104ab --- /dev/null +++ b/backend/migrations/2024-07-14-091228_add-area-table/down.sql @@ -0,0 +1,2 @@ +DROP TABLE areas; +DROP TYPE area_type; diff --git a/backend/migrations/2024-07-14-091228_add-area-table/up.sql b/backend/migrations/2024-07-14-091228_add-area-table/up.sql new file mode 100644 index 0000000..1451107 --- /dev/null +++ b/backend/migrations/2024-07-14-091228_add-area-table/up.sql @@ -0,0 +1,9 @@ +-- buurt: neighbourhood, wijk: district, gebied: area, stadsdeel: borough +CREATE TYPE area_type AS ENUM('neighbourhood', 'district', 'area', 'borough'); + +CREATE TABLE areas ( + id SERIAL PRIMARY KEY, + name varchar NOT NULL, + area GEOMETRY NOT NULL, + area_type area_type NOT NULL +); diff --git a/backend/src/db/sql_types.rs b/backend/src/db/sql_types.rs index a7333c9..0b4b664 100644 --- a/backend/src/db/sql_types.rs +++ b/backend/src/db/sql_types.rs @@ -51,3 +51,7 @@ impl FromSql for UserRoleEnum { } } } + +#[derive(SqlType)] +#[diesel(postgres_type(name = "AreaType"))] +pub struct AreaType; diff --git a/backend/src/schema.rs b/backend/src/schema.rs index 9ef40b1..ed74777 100644 --- a/backend/src/schema.rs +++ b/backend/src/schema.rs @@ -1,5 +1,18 @@ // @generated automatically by Diesel CLI. +diesel::table! { + use postgis_diesel::sql_types::*; + use diesel::sql_types::*; + use crate::db::sql_types::*; + + areas (id) { + id -> Int4, + name -> Varchar, + area -> Geometry, + area_type -> AreaType, + } +} + diesel::table! { use postgis_diesel::sql_types::*; use diesel::sql_types::*; @@ -64,6 +77,7 @@ diesel::joinable!(visits -> locations (location_id)); diesel::joinable!(visits -> users (user_id)); diesel::allow_tables_to_appear_in_same_query!( + areas, locations, spatial_ref_sys, users,