-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c7d70be
commit 3b86be5
Showing
30 changed files
with
517 additions
and
30 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
libs/@local/graph/migrations/graph-migrations/v001__extensions/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- We cannot remove the extensions again as extensions are global |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
libs/@local/graph/migrations/graph-migrations/v001__extensions/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CREATE EXTENSION IF NOT EXISTS btree_gist; | ||
CREATE EXTENSION IF NOT EXISTS vector; |
1 change: 0 additions & 1 deletion
1
libs/@local/graph/migrations/graph-migrations/v001__initial_setup/down.sql
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
libs/@local/graph/migrations/graph-migrations/v001__initial_setup/up.sql
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
libs/@local/graph/migrations/graph-migrations/v002__accounts/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE accounts; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v002__accounts/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct Accounts; | ||
|
||
impl Migration for Accounts { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
libs/@local/graph/migrations/graph-migrations/v002__accounts/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE accounts ( | ||
account_id UUID PRIMARY KEY | ||
); |
24 changes: 0 additions & 24 deletions
24
libs/@local/graph/migrations/graph-migrations/v002__advanced_setup.rs
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
libs/@local/graph/migrations/graph-migrations/v003__account_groups/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE account_groups; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v003__account_groups/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct AccountGroups; | ||
|
||
impl Migration for AccountGroups { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
libs/@local/graph/migrations/graph-migrations/v003__account_groups/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE account_groups ( | ||
account_group_id UUID PRIMARY KEY | ||
); |
1 change: 1 addition & 0 deletions
1
libs/@local/graph/migrations/graph-migrations/v004__webs/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE webs; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v004__webs/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct Webs; | ||
|
||
impl Migration for Webs { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
libs/@local/graph/migrations/graph-migrations/v004__webs/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CREATE TABLE webs ( | ||
web_id UUID PRIMARY KEY | ||
); |
6 changes: 6 additions & 0 deletions
6
libs/@local/graph/migrations/graph-migrations/v005__common_ontology/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DROP VIEW ontology_additional_metadata; | ||
DROP TABLE ontology_temporal_metadata; | ||
DROP TABLE ontology_owned_metadata; | ||
DROP TABLE ontology_external_metadata; | ||
DROP TABLE ontology_ids; | ||
DROP TABLE base_urls; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v005__common_ontology/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct CommonOntology; | ||
|
||
impl Migration for CommonOntology { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
libs/@local/graph/migrations/graph-migrations/v005__common_ontology/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
CREATE TABLE base_urls ( | ||
base_url TEXT PRIMARY KEY | ||
); | ||
|
||
CREATE TABLE ontology_ids ( | ||
ontology_id UUID PRIMARY KEY, | ||
base_url TEXT NOT NULL REFERENCES base_urls, | ||
version BIGINT NOT NULL, | ||
UNIQUE (base_url, version) | ||
); | ||
|
||
CREATE TABLE ontology_owned_metadata ( | ||
ontology_id UUID PRIMARY KEY REFERENCES ontology_ids, | ||
web_id UUID NOT NULL REFERENCES webs | ||
); | ||
|
||
CREATE TABLE ontology_external_metadata ( | ||
ontology_id UUID PRIMARY KEY REFERENCES ontology_ids, | ||
fetched_at TIMESTAMP WITH TIME ZONE NOT NULL | ||
); | ||
|
||
CREATE TABLE ontology_temporal_metadata ( | ||
ontology_id UUID NOT NULL REFERENCES ontology_ids, | ||
transaction_time TSTZRANGE NOT NULL, | ||
provenance JSONB NOT NULL, | ||
EXCLUDE USING gist ( | ||
ontology_id WITH =, | ||
transaction_time WITH && | ||
) | ||
); | ||
|
||
CREATE VIEW ontology_additional_metadata AS | ||
SELECT | ||
ontology_owned_metadata.ontology_id, | ||
jsonb_build_object( | ||
'web_id', | ||
ontology_owned_metadata.web_id | ||
) AS additional_metadata | ||
FROM ontology_owned_metadata | ||
UNION ALL | ||
SELECT | ||
ontology_external_metadata.ontology_id, | ||
jsonb_build_object( | ||
'fetched_at', | ||
ontology_external_metadata.fetched_at | ||
) AS additional_metadata | ||
FROM ontology_external_metadata; |
7 changes: 7 additions & 0 deletions
7
libs/@local/graph/migrations/graph-migrations/v006__data_types/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DROP VIEW data_type_conversion_aggregation; | ||
DROP TABLE data_type_conversions; | ||
DROP TABLE data_type_embeddings; | ||
DROP TABLE data_type_constrains_values_on; | ||
DROP VIEW data_type_inherits_from_aggregation; | ||
DROP TABLE data_type_inherits_from; | ||
DROP TABLE data_types; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v006__data_types/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct DataTypes; | ||
|
||
impl Migration for DataTypes { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
libs/@local/graph/migrations/graph-migrations/v006__data_types/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
CREATE TABLE data_types ( | ||
ontology_id UUID PRIMARY KEY REFERENCES ontology_ids, | ||
schema JSONB NOT NULL, | ||
closed_schema JSONB NOT NULL | ||
); | ||
|
||
CREATE TABLE data_type_inherits_from ( | ||
source_data_type_ontology_id UUID REFERENCES data_types, | ||
target_data_type_ontology_id UUID REFERENCES data_types, | ||
depth INT NOT NULL, | ||
UNIQUE (source_data_type_ontology_id, target_data_type_ontology_id) | ||
); | ||
|
||
CREATE VIEW data_type_inherits_from_aggregation AS | ||
SELECT | ||
data_type_inherits_from.source_data_type_ontology_id, | ||
array_agg( | ||
data_type_inherits_from.target_data_type_ontology_id | ||
) AS target_data_type_ontology_ids, | ||
array_agg(data_type_inherits_from.depth) AS depths | ||
FROM data_type_inherits_from | ||
GROUP BY data_type_inherits_from.source_data_type_ontology_id; | ||
|
||
|
||
CREATE TABLE data_type_constrains_values_on ( | ||
source_data_type_ontology_id UUID NOT NULL REFERENCES data_types, | ||
target_data_type_ontology_id UUID NOT NULL REFERENCES data_types | ||
); | ||
|
||
CREATE TABLE data_type_embeddings ( | ||
ontology_id UUID PRIMARY KEY REFERENCES data_types, | ||
embedding VECTOR(3072) NOT NULL, | ||
updated_at_transaction_time TIMESTAMP WITH TIME ZONE NOT NULL | ||
); | ||
|
||
CREATE TABLE data_type_conversions ( | ||
source_data_type_ontology_id UUID PRIMARY KEY REFERENCES data_types, | ||
target_data_type_base_url TEXT NOT NULL REFERENCES base_urls, | ||
"into" JSONB NOT NULL, | ||
"from" JSONB NOT NULL | ||
); | ||
|
||
CREATE VIEW data_type_conversion_aggregation AS | ||
SELECT | ||
source_data_type_ontology_id, | ||
array_agg(target_data_type_base_url) AS target_data_type_base_urls, | ||
array_agg("into") AS intos, | ||
array_agg("from") AS froms | ||
FROM data_type_conversions | ||
GROUP BY source_data_type_ontology_id; |
4 changes: 4 additions & 0 deletions
4
libs/@local/graph/migrations/graph-migrations/v007__property_types/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
DROP TABLE property_type_embeddings; | ||
DROP TABLE property_type_constrains_properties_on; | ||
DROP TABLE property_type_constrains_values_on; | ||
DROP TABLE property_types; |
26 changes: 26 additions & 0 deletions
26
libs/@local/graph/migrations/graph-migrations/v007__property_types/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use error_stack::Report; | ||
use hash_graph_migrations::{Context, Migration}; | ||
use tokio_postgres::Client; | ||
|
||
pub struct PropertyTypes; | ||
|
||
impl Migration for PropertyTypes { | ||
type Context = Client; | ||
type Error = tokio_postgres::Error; | ||
|
||
async fn up( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("up.sql")).await?; | ||
Ok(()) | ||
} | ||
|
||
async fn down( | ||
self, | ||
context: &mut <Self::Context as Context>::Transaction<'_>, | ||
) -> Result<(), Report<Self::Error>> { | ||
context.simple_query(include_str!("down.sql")).await?; | ||
Ok(()) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
libs/@local/graph/migrations/graph-migrations/v007__property_types/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE TABLE property_types ( | ||
ontology_id UUID PRIMARY KEY REFERENCES ontology_ids, | ||
schema JSONB NOT NULL | ||
); | ||
|
||
CREATE TABLE property_type_constrains_values_on ( | ||
source_property_type_ontology_id UUID NOT NULL REFERENCES property_types, | ||
target_data_type_ontology_id UUID NOT NULL REFERENCES data_types | ||
); | ||
|
||
CREATE TABLE property_type_constrains_properties_on ( | ||
source_property_type_ontology_id UUID NOT NULL REFERENCES property_types, | ||
target_property_type_ontology_id UUID NOT NULL REFERENCES property_types | ||
); | ||
|
||
CREATE TABLE property_type_embeddings ( | ||
ontology_id UUID PRIMARY KEY REFERENCES property_types, | ||
embedding VECTOR(3072) NOT NULL, | ||
updated_at_transaction_time TIMESTAMP WITH TIME ZONE NOT NULL | ||
); |
6 changes: 6 additions & 0 deletions
6
libs/@local/graph/migrations/graph-migrations/v008__entity_types/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DROP TABLE entity_type_embeddings; | ||
DROP TABLE entity_type_constrains_link_destinations_on; | ||
DROP TABLE entity_type_constrains_links_on; | ||
DROP TABLE entity_type_constrains_properties_on; | ||
DROP TABLE entity_type_inherits_from; | ||
DROP TABLE entity_types; |
Oops, something went wrong.