Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJ-2008: json-based entities POC #3026

Draft
wants to merge 29 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
729d811
beginning of POC
davidangb Sep 10, 2024
9536d34
liquibase for schema changes (no references yet)
davidangb Sep 10, 2024
761bd55
streamline triggers
davidangb Sep 11, 2024
262a6e6
add TODOs
davidangb Sep 11, 2024
2465994
entityTypeMetadata
davidangb Sep 11, 2024
3de8044
basic entityQuery
davidangb Sep 11, 2024
3e707d6
very basic batchUpsert
davidangb Sep 11, 2024
bbeadd6
entityQuery metadata
davidangb Sep 11, 2024
aa5dfa8
query sorting
davidangb Sep 11, 2024
9d62b0c
Merge branch 'develop' into da_entityServiceJson
davidangb Sep 11, 2024
7897d70
fix ENTITY_KEYS insert trigger for null attributes
davidangb Sep 11, 2024
18eff97
fix old-schema inserts
davidangb Sep 11, 2024
e7dea70
beginning of handling refs
davidangb Sep 11, 2024
868caac
batch upsert optimizations
davidangb Sep 18, 2024
6727cb3
debug logging
davidangb Sep 18, 2024
36ab8c0
two steps forward, one step back
davidangb Sep 18, 2024
d229741
more batchUpsert work
davidangb Sep 24, 2024
cfb6f86
createEntity is an insert
davidangb Sep 25, 2024
26b4e6f
cleanups
davidangb Sep 25, 2024
e6c782c
delete entities
davidangb Sep 25, 2024
b0d0fdf
recursion limit; stopwatch timing
davidangb Sep 25, 2024
6cfd993
timing for perf tests
davidangb Sep 26, 2024
c7728d2
handle references in bulk
davidangb Sep 26, 2024
2f0af75
code comment
davidangb Sep 27, 2024
5a9bd18
Merge branch 'develop' into da_entityServiceJson
davidangb Sep 27, 2024
4380138
rename entity
davidangb Sep 27, 2024
14c64a4
Merge branch 'develop' into da_entityServiceJson
davidangb Dec 5, 2024
f704053
Merge branch 'develop' into da_entityServiceJson
davidangb Feb 28, 2025
1117635
Merge branch 'develop' into da_entityServiceJson
davidangb Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<include file="changesets/20240418_workspace_monitor_args.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240723_workspace_settings.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240820_submission_cost_cap_threshold.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240910_entity_json_support.xml" relativeToChangelogFile="true"/>
<include file="changesets/20240830_workflow_cost.xml" relativeToChangelogFile="true"/>
<include file="changesets/20241106_streamline_entity_attr_temp_table_procedure.xml" relativeToChangelogFile="true"/>
<include file="changesets/20241106_streamline_workspace_attr_temp_table_procedure.xml" relativeToChangelogFile="true"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="dummy" xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.29.xsd">

<!-- add the ENTITY.attributes JSON column -->
<changeSet logicalFilePath="dummy" author="davidan" id="add_attributes_col_to_entity">
<addColumn tableName="ENTITY">
<column name="attributes" type="JSON"/>
</addColumn>
</changeSet>

<!-- create the ENTITY_KEYS table -->
<changeSet logicalFilePath="dummy" author="davidan" id="create_table_entity_keys">
<createTable tableName="ENTITY_KEYS">
<column name="id" type="BIGINT UNSIGNED">
<constraints primaryKey="true"
nullable="false"
referencedTableName="ENTITY" referencedColumnNames="id"
foreignKeyName="fk_entity_keys_entity_id" deleteCascade="true"/>
</column>
<column name="workspace_id" type="BINARY(16)">
<constraints nullable="false"
referencedTableName="WORKSPACE" referencedColumnNames="id"
foreignKeyName="fk_entity_keys_workspace_id" deleteCascade="true"/>
</column>
<column name="entity_type" type="VARCHAR(254)">
<constraints nullable="false"/>
</column>
<column name="attribute_keys" type="JSON">
<constraints nullable="false"/>
</column>
<column name="last_updated" type="TIMESTAMP(3)">
<constraints nullable="false"/>
</column>
</createTable>
<createIndex indexName="idx_entity_keys_workspace_and_entity_type" tableName="ENTITY_KEYS" unique="false">
<column name="workspace_id"/>
<column name="entity_type"/>
</createIndex>
<createIndex indexName="idx_entity_keys_last_updated_desc" tableName="ENTITY_KEYS" unique="false">
<column name="last_updated" descending="true"/>
</createIndex>
</changeSet>

<!-- create the ENTITY triggers to populate ENTITY_KEYS -->
<changeSet logicalFilePath="dummy" author="davidan" id="entity_keys_triggers">
<sql stripComments="true" endDelimiter="~">
DROP TRIGGER IF EXISTS after_entity_insert ~
DROP TRIGGER IF EXISTS after_entity_update ~

CREATE TRIGGER after_entity_insert AFTER INSERT ON ENTITY
FOR EACH ROW
if new.attributes is not null then
INSERT INTO ENTITY_KEYS
(id, workspace_id, entity_type, attribute_keys, last_updated)
VALUES
(new.id, new.workspace_id, new.entity_type, JSON_KEYS(new.attributes), now(3));
end if ~

CREATE TRIGGER after_entity_update AFTER UPDATE ON ENTITY
FOR EACH ROW
BEGIN
-- is this row soft-deleted?
if old.deleted = 0 and new.deleted = 1 then
DELETE FROM ENTITY_KEYS WHERE id = new.id;
elseif new.attributes is not null then
-- compare old keys to new keys; update the ENTITY_KEYS table only if they are different
set @new_keys := JSON_KEYS(new.attributes);
set @old_keys := JSON_KEYS(old.attributes);
if JSON_LENGTH(@new_keys) != JSON_LENGTH(@old_keys) OR JSON_CONTAINS(@new_keys, @old_keys) = 0 then
UPDATE ENTITY_KEYS SET attribute_keys=@new_keys, last_updated=now(3)
WHERE id = new.id;
end if;
end if;
END ~
</sql>
<rollback>
DROP TRIGGER IF EXISTS after_entity_insert;
DROP TRIGGER IF EXISTS after_entity_update;
</rollback>
</changeSet>

<!-- create the ENTITY_REFS table -->
<changeSet logicalFilePath="dummy" author="davidan" id="create_table_entity_refs">
<createTable tableName="ENTITY_REFS">
<column name="from_id" type="BIGINT UNSIGNED">
<constraints nullable="false" />
</column>
<column name="to_id" type="BIGINT UNSIGNED">
<constraints nullable="false" />
</column>
</createTable>
<!-- index for lookups against to_id -->
<createIndex tableName="ENTITY_REFS" indexName="idx_to">
<column name="to_id" />
</createIndex>
<!-- unique constraint for from+to, which covers lookups against from_id -->
<addUniqueConstraint columnNames="from_id, to_id" constraintName="unq_from_to" tableName="ENTITY_REFS"/>
</changeSet>




</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait DataAccess
with RawlsBillingProjectComponent
with WorkspaceComponent
with EntityComponent
with JsonEntityComponent
with AttributeComponent
with MethodConfigurationComponent
with SubmissionComponent
Expand Down
Loading