Elffuss BraidHub

kikocis/EDC public

main · 2.0 KiBSourceRawPermalink

SQL Asset

Provides SQL persistence for assets.

Prerequisites

Please apply this schema to your SQL database.

Entity Diagram

ER Diagram

Migrate from 0.3.1 to 0.3.2

This table structure has been changed, from 3 tables (one for the asset, one for properties and one for data address) to a single table with json fields. To migrate an existing database, please first add the 3 new columns in the edc_asset table:

ALTER TABLE edc_asset
    ADD COLUMN properties         json DEFAULT '{}',
    ADD COLUMN private_properties json DEFAULT '{}',
    ADD COLUMN data_address       json DEFAULT '{}';

Then migrate the existing data in the new format:

UPDATE edc_asset
SET properties=(SELECT JSON_OBJECT_AGG(property_name, property_value)
                FROM edc_asset_property
                WHERE asset_id_fk = edc_asset.asset_id
                  AND property_is_private = FALSE),
    private_properties=(SELECT JSON_OBJECT_AGG(property_name, property_value)
                        FROM edc_asset_property
                        WHERE asset_id_fk = edc_asset.asset_id
                          AND property_is_private = TRUE),
    data_address=(SELECT properties FROM edc_asset_dataaddress WHERE asset_id_fk = edc_asset.asset_id);

After the migration, the tables edc_asset_dataaddress and edc_asset_property can be deleted.