Skip to content

Commit

Permalink
removed extension-definition object_ref table, added fk to SMOs
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza committed Sep 13, 2024
1 parent 27fbfa3 commit 9814e6c
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions stix2/datastore/relational_db/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,34 +470,34 @@ def generate_table_information(self, name, **kwargs): # noqa: F811
@add_method(IDProperty)
def generate_table_information(self, name, **kwargs): # noqa: F811
schema_name = kwargs.get('schema_name')
if schema_name == "sro":
# sro common properties are the same as sdo's
if schema_name in ["sro", "common"]:
# sro, smo common properties are the same as sdo's
schema_name = "sdo"
table_name = kwargs.get("table_name")
if schema_name == "common":
return Column(
name,
Text,
CheckConstraint(
f"{name} ~ '^{table_name}" + "--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'",
# noqa: E131
),
primary_key=True,
nullable=not (self.required),
)
else:
foreign_key_column = f"common.core_{schema_name}.id"
return Column(
name,
Text,
ForeignKey(foreign_key_column, ondelete="CASCADE"),
CheckConstraint(
f"{name} ~ '^{table_name}" + "--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'",
# noqa: E131
),
primary_key=True,
nullable=not (self.required),
)
# if schema_name == "common":
# return Column(
# name,
# Text,
# CheckConstraint(
# f"{name} ~ '^{table_name}" + "--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'",
# # noqa: E131
# ),
# primary_key=True,
# nullable=not (self.required),
# )
# else:
foreign_key_column = f"common.core_{schema_name}.id"
return Column(
name,
Text,
ForeignKey(foreign_key_column, ondelete="CASCADE"),
CheckConstraint(
f"{name} ~ '^{table_name}" + "--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$'",
# noqa: E131
),
primary_key=True,
nullable=not (self.required),
)

return Column(
name,
Expand Down Expand Up @@ -684,7 +684,7 @@ def generate_object_table(
table_name = parent_table_name + "_" + table_name
if is_embedded_object:
core_properties = list()
elif schema_name in ["sdo", "sro"]:
elif schema_name in ["sdo", "sro", "common"]:
core_properties = SDO_COMMON_PROPERTIES
elif schema_name == "sco":
core_properties = SCO_COMMON_PROPERTIES
Expand Down

0 comments on commit 9814e6c

Please sign in to comment.