From 2d3421e2c37e4639f9cab3bf6f379d683df7c844 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 14 Nov 2024 06:23:38 +0100 Subject: [PATCH] `core`: Create migration for metadata tables --- .idea/dataSources.xml | 12 +++++ .idea/sqldialects.xml | 6 +++ .../down.sql | 8 ++++ .../up.sql | 47 +++++++++++++++++++ acrate-core/src/schema.rs | 46 ++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 .idea/dataSources.xml create mode 100644 .idea/sqldialects.xml create mode 100644 acrate-core/migrations/2024-11-14-031744_Add webfinger table/down.sql create mode 100644 acrate-core/migrations/2024-11-14-031744_Add webfinger table/up.sql create mode 100644 acrate-core/src/schema.rs diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..6cfc387 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + postgresql + true + org.postgresql.Driver + jdbc:postgresql:///acrate + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml new file mode 100644 index 0000000..610ed0f --- /dev/null +++ b/.idea/sqldialects.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/acrate-core/migrations/2024-11-14-031744_Add webfinger table/down.sql b/acrate-core/migrations/2024-11-14-031744_Add webfinger table/down.sql new file mode 100644 index 0000000..af9bea0 --- /dev/null +++ b/acrate-core/migrations/2024-11-14-031744_Add webfinger table/down.sql @@ -0,0 +1,8 @@ +DROP FUNCTION get_meta_property; +DROP FUNCTION get_meta_link; +DROP FUNCTION get_meta_aliases; + +DROP TABLE meta_property; +DROP TABLE meta_link_property; +DROP TABLE meta_link; +DROP TABLE meta_alias; diff --git a/acrate-core/migrations/2024-11-14-031744_Add webfinger table/up.sql b/acrate-core/migrations/2024-11-14-031744_Add webfinger table/up.sql new file mode 100644 index 0000000..664d409 --- /dev/null +++ b/acrate-core/migrations/2024-11-14-031744_Add webfinger table/up.sql @@ -0,0 +1,47 @@ +CREATE TABLE meta_alias ( + id UUID DEFAULT gen_random_uuid(), + pattern BPCHAR NOT NULL, + alias BPCHAR NOT NULL, + + CONSTRAINT unique_aliases UNIQUE (alias), + PRIMARY KEY (id) +); + +CREATE TABLE meta_link ( + id UUID DEFAULT gen_random_uuid(), + pattern BPCHAR NOT NULL, + rel BPCHAR NOT NULL, + type BPCHAR, + href BPCHAR, + + PRIMARY KEY (id) +); + +CREATE TABLE meta_link_property ( + id UUID DEFAULT gen_random_uuid(), + link UUID REFERENCES meta_link (id), + rel BPCHAR NOT NULL, + value BPCHAR, + + PRIMARY KEY (id) +); + +CREATE TABLE meta_property ( + id UUID DEFAULT gen_random_uuid(), + pattern BPCHAR NOT NULL, + value BPCHAR, + + PRIMARY KEY (id) +); + +CREATE FUNCTION get_meta_aliases(BPCHAR) RETURNS SETOF meta_alias AS $$ + SELECT * FROM meta_alias WHERE meta_alias.pattern ILIKE $1; +$$ LANGUAGE SQL; + +CREATE FUNCTION get_meta_link(BPCHAR) RETURNS SETOF meta_link AS $$ + SELECT * FROM meta_link WHERE meta_link.pattern ILIKE $1; +$$ LANGUAGE SQL; + +CREATE FUNCTION get_meta_property(BPCHAR) RETURNS SETOF meta_property AS $$ + SELECT * FROM meta_property WHERE meta_property.pattern ILIKE $1; +$$ LANGUAGE SQL; diff --git a/acrate-core/src/schema.rs b/acrate-core/src/schema.rs new file mode 100644 index 0000000..913e83e --- /dev/null +++ b/acrate-core/src/schema.rs @@ -0,0 +1,46 @@ +// @generated automatically by Diesel CLI. + +diesel::table! { + meta_alias (id) { + id -> Uuid, + pattern -> Bpchar, + alias -> Bpchar, + } +} + +diesel::table! { + meta_link (id) { + id -> Uuid, + pattern -> Bpchar, + rel -> Bpchar, + #[sql_name = "type"] + type_ -> Nullable, + href -> Nullable, + } +} + +diesel::table! { + meta_link_property (id) { + id -> Uuid, + link -> Nullable, + rel -> Bpchar, + value -> Nullable, + } +} + +diesel::table! { + meta_property (id) { + id -> Uuid, + pattern -> Bpchar, + value -> Nullable, + } +} + +diesel::joinable!(meta_link_property -> meta_link (link)); + +diesel::allow_tables_to_appear_in_same_query!( + meta_alias, + meta_link, + meta_link_property, + meta_property, +);