11# from collections import OrderedDict
22
33from sqlalchemy import ( # create_engine,; insert,
4- ARRAY , TIMESTAMP , Boolean , CheckConstraint , Column , Float , ForeignKey ,
5- Integer , LargeBinary , Table , Text , UniqueConstraint ,
4+ ARRAY , TIMESTAMP , Boolean , CheckConstraint , Column , ForeignKey ,
5+ Integer , Table , Text , UniqueConstraint
66)
77
88from stix2 .datastore .relational_db .add_method import add_method
@@ -60,7 +60,7 @@ def create_array_child_table(metadata, db_backend, table_name, property_name, co
6060 nullable = False ,
6161 ),
6262 ]
63- return Table (canonicalize_table_name (table_name + "_" + "selector" , schema_name ), metadata , * columns )
63+ return Table (canonicalize_table_name (table_name + "_" + "selector" ), metadata , * columns , schema = schema_name )
6464
6565
6666def derive_column_name (prop ):
@@ -171,11 +171,12 @@ def create_kill_chain_phases_table(name, metadata, db_backend, schema_name, tabl
171171
172172
173173def create_granular_markings_table (metadata , db_backend , sco_or_sdo ):
174+ schema_name = db_backend .schema_for_core ()
174175 columns = [
175176 Column (
176177 "id" ,
177178 db_backend .determine_sql_type_for_key_as_id (),
178- ForeignKey ("common. core_" + sco_or_sdo + ".id" , ondelete = "CASCADE" ),
179+ ForeignKey (canonicalize_table_name ( " core_" + sco_or_sdo , schema_name ) + ".id" , ondelete = "CASCADE" ),
179180 nullable = False ,
180181 primary_key = True ,
181182 ),
@@ -197,14 +198,15 @@ def create_granular_markings_table(metadata, db_backend, sco_or_sdo):
197198
198199 tables = [
199200 Table (
200- canonicalize_table_name ("granular_marking_" + sco_or_sdo , db_backend . schema_for_core () ),
201+ canonicalize_table_name ("granular_marking_" + sco_or_sdo ),
201202 metadata ,
202203 * columns ,
203204 CheckConstraint (
204205 """(lang IS NULL AND marking_ref IS NOT NULL)
205206 OR
206207 (lang IS NOT NULL AND marking_ref IS NULL)""" ,
207208 ),
209+ schema = schema_name
208210 ),
209211 ]
210212 if child_table :
0 commit comments