Skip to content

Commit

Permalink
feat: Add areas table migration
Browse files Browse the repository at this point in the history
  • Loading branch information
SchutteJan committed Jul 14, 2024
1 parent 18a5b77 commit 95c7b26
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/migrations/2024-07-14-091228_add-area-table/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE areas;
DROP TYPE area_type;
9 changes: 9 additions & 0 deletions backend/migrations/2024-07-14-091228_add-area-table/up.sql
Original file line number Diff line number Diff line change
@@ -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
);
4 changes: 4 additions & 0 deletions backend/src/db/sql_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ impl FromSql<UserRole, Pg> for UserRoleEnum {
}
}
}

#[derive(SqlType)]
#[diesel(postgres_type(name = "AreaType"))]
pub struct AreaType;
14 changes: 14 additions & 0 deletions backend/src/schema.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 95c7b26

Please sign in to comment.