Skip to content

Commit d6103bb

Browse files
author
Alex Meadows
committed
process_tracker_python-86 Add Source Object Attribute Lookup
✨ Source Object Attributes can now be registered ✨ Attributes can be associated to processes as sources or targets Attributes can now be registered for processes and data sources. This allows for metadata injection within scripts.
1 parent 45c4697 commit d6103bb

File tree

6 files changed

+443
-11
lines changed

6 files changed

+443
-11
lines changed

dbscripts/mysql_process_tracker.sql

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
USE process_tracker;
22

3+
create table process_tracker.data_type_lkup
4+
(
5+
data_type_id int auto_increment
6+
primary key,
7+
data_type varchar(75) not null,
8+
constraint data_type_lkup_data_type_uindex
9+
unique (data_type)
10+
);
11+
312
create table contact_lkup
413
(
514
contact_id int auto_increment
@@ -439,3 +448,49 @@ create table process_contact
439448
foreign key (contact_id) references contact_lkup (contact_id)
440449
);
441450

451+
create table source_object_attribute
452+
(
453+
source_object_attribute_id int auto_increment
454+
primary key,
455+
source_object_attribute_name varchar(250) not null,
456+
source_object_id int not null,
457+
attribute_path varchar(750) null,
458+
data_type_id int null,
459+
data_length int null,
460+
data_decimal int null,
461+
is_pii tinyint(1) default 0 not null,
462+
default_value_string varchar(250) null,
463+
default_value_number decimal null,
464+
constraint source_object_attribute_udx01
465+
unique (source_object_id, source_object_attribute_name),
466+
constraint source_object_attribute_fk01
467+
foreign key (source_object_id) references source_object_lkup (source_object_id),
468+
constraint source_object_attribute_fk02
469+
foreign key (data_type_id) references data_type_lkup (data_type_id)
470+
);
471+
472+
create table process_source_object_attribute
473+
(
474+
process_id int not null,
475+
source_object_attribute_id int not null,
476+
source_object_attribute_alias varchar(250) null,
477+
source_object_attribute_expression varchar(250) null,
478+
primary key (process_id, source_object_attribute_id),
479+
constraint process_source_object_attribute_fk01
480+
foreign key (process_id) references process (process_id),
481+
constraint process_source_object_attribute_fk02
482+
foreign key (source_object_attribute_id) references source_object_attribute (source_object_attribute_id)
483+
);
484+
485+
create table if not exists process_target_object_attribute
486+
(
487+
process_id int not null,
488+
target_object_attribute_id int not null,
489+
target_object_attribute_alias varchar(250) null,
490+
target_object_attribute_expression varchar(250) null,
491+
primary key (process_id, target_object_attribute_id),
492+
constraint process_target_object_attribute_fk01
493+
foreign key (process_id) references process (process_id),
494+
constraint process_target_object_attribute_fk02
495+
foreign key (target_object_attribute_id) references source_object_attribute (source_object_attribute_id)
496+
);

dbscripts/postgresql_process_tracker.sql

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ create schema process_tracker;
44

55
alter schema process_tracker owner to pt_admin;
66

7+
create table process_tracker.data_type_lkup
8+
(
9+
data_type_id serial not null
10+
constraint data_type_lkup_pk
11+
primary key,
12+
data_type varchar(75) not null
13+
);
14+
15+
alter table process_tracker.data_type_lkup owner to pt_admin;
16+
17+
create unique index data_type_lkup_data_type_uindex
18+
on process_tracker.data_type_lkup (data_type);
19+
20+
21+
722
create table process_tracker.contact_lkup
823
(
924
contact_id serial not null
@@ -630,4 +645,62 @@ create table process_contact
630645
primary key (process_id, contact_id)
631646
);
632647

633-
alter table process_contact owner to pt_admin;
648+
alter table process_contact owner to pt_admin;
649+
650+
create table process_tracker.source_object_attribute
651+
(
652+
source_object_attribute_id serial not null
653+
constraint source_object_attribute_pk
654+
primary key,
655+
source_object_attribute_name varchar(250) not null,
656+
source_object_id integer
657+
constraint source_object_attribute_fk01
658+
references process_tracker.source_object_lkup,
659+
attribute_path varchar(750),
660+
data_type_id integer
661+
constraint source_object_attribute_fk02
662+
references process_tracker.data_type_lkup,
663+
data_length integer,
664+
data_decimal integer,
665+
is_pii boolean default false not null,
666+
default_value_string varchar(250),
667+
default_value_number numeric
668+
);
669+
670+
alter table process_tracker.source_object_attribute owner to pt_admin;
671+
672+
create unique index source_object_attribute_udx01
673+
on process_tracker.source_object_attribute (source_object_id, source_object_attribute_name);
674+
675+
create table process_tracker.process_target_object_attribute
676+
(
677+
process_id integer not null
678+
constraint process_target_object_attribute_fk01
679+
references process_tracker.process,
680+
target_object_attribute_id integer not null
681+
constraint process_target_object_attribute_fk02
682+
references process_tracker.source_object_attribute,
683+
target_object_attribute_alias varchar(250),
684+
target_object_attribute_expression varchar(250),
685+
constraint process_target_object_attribute_pk
686+
primary key (process_id, target_object_attribute_id)
687+
);
688+
689+
alter table process_tracker.process_target_object_attribute owner to pt_admin;
690+
691+
create table process_tracker.process_source_object_attribute
692+
(
693+
process_id integer not null
694+
constraint process_source_object_attribute_fk01
695+
references process_tracker.process,
696+
source_object_attribute_id integer not null
697+
constraint process_source_object_attribute_fk02
698+
references process_tracker.source_object_attribute,
699+
source_object_attribute_alias varchar(250),
700+
source_object_attribute_expression varchar(250),
701+
constraint process_source_object_attribute_pk
702+
primary key (process_id, source_object_attribute_id)
703+
);
704+
705+
alter table process_tracker.process_source_object_attribute owner to pt_admin;
706+

process_tracker/models/process.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,37 @@ def __repr__(self):
282282
)
283283

284284

285+
class ProcessSourceObjectAttribute(Base):
286+
__tablename__ = "process_source_object_attribute"
287+
__table_args__ = {"schema": "process_tracker"}
288+
289+
process_id = Column(
290+
Integer,
291+
ForeignKey("process_tracker.process.process_id"),
292+
primary_key=True,
293+
nullable=False,
294+
)
295+
source_object_attribute_id = Column(
296+
Integer,
297+
ForeignKey(
298+
"process_tracker.source_object_attribute.source_object_attribute_id"
299+
),
300+
primary_key=True,
301+
nullable=False,
302+
)
303+
source_object_attribute_alias = Column(String(250), nullable=True)
304+
source_object_attribute_expression = Column(String(250), nullable=True)
305+
306+
attributes = relationship("SourceObjectAttribute")
307+
processes = relationship("Process")
308+
309+
def __repr__(self):
310+
return "<ProcessSourceObjectAttribute process_id=%s, attribute_id=%s>" % (
311+
self.process_id,
312+
self.source_object_attribute_id,
313+
)
314+
315+
285316
class ProcessTarget(Base):
286317
__tablename__ = "process_target"
287318
__table_args__ = {"schema": "process_tracker"}
@@ -337,6 +368,37 @@ def __repr__(self):
337368
)
338369

339370

371+
class ProcessTargetObjectAttribute(Base):
372+
__tablename__ = "process_target_object_attribute"
373+
__table_args__ = {"schema": "process_tracker"}
374+
375+
process_id = Column(
376+
Integer,
377+
ForeignKey("process_tracker.process.process_id"),
378+
primary_key=True,
379+
nullable=False,
380+
)
381+
target_object_attribute_id = Column(
382+
Integer,
383+
ForeignKey(
384+
"process_tracker.source_object_attribute.source_object_attribute_id"
385+
),
386+
primary_key=True,
387+
nullable=False,
388+
)
389+
target_object_attribute_alias = Column(String(250), nullable=True)
390+
target_object_attribute_expression = Column(String(250), nullable=True)
391+
392+
attributes = relationship("SourceObjectAttribute")
393+
processes = relationship("Process")
394+
395+
def __repr__(self):
396+
return "<ProcessTargetObjectAttribute process_id=%s, attribute_id=%s>" % (
397+
self.process_id,
398+
self.source_object_attribute_id,
399+
)
400+
401+
340402
class ProcessDependency(Base):
341403

342404
__tablename__ = "process_dependency"

process_tracker/models/source.py

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,39 @@
11
# SQLAlchemy Models
22
# Models for Source entities
33

4-
from sqlalchemy import Column, ForeignKey, Integer, Sequence, String, UniqueConstraint
4+
from sqlalchemy import (
5+
Boolean,
6+
Column,
7+
ForeignKey,
8+
Integer,
9+
Numeric,
10+
Sequence,
11+
String,
12+
UniqueConstraint,
13+
)
514
from sqlalchemy.orm import relationship
615

716
from process_tracker.models.model_base import Base
817

918

19+
class DataType(Base):
20+
21+
__tablename__ = "data_type_lkup"
22+
__table_args__ = {"schema": "process_tracker"}
23+
24+
data_type_id = Column(
25+
Integer,
26+
Sequence("data_type_lkup_data_type_id", schema="process_tracker"),
27+
primary_key=True,
28+
nullable=False,
29+
)
30+
data_type = Column(String(75), unique=True, nullable=False)
31+
32+
def __repr__(self):
33+
34+
return "<DataType id=%s, name=%s>" % (self.data_type_id, self.data_type)
35+
36+
1037
class DatasetType(Base):
1138

1239
__tablename__ = "dataset_type_lkup"
@@ -143,6 +170,49 @@ def __repr__(self):
143170
)
144171

145172

173+
class SourceObjectAttribute(Base):
174+
175+
__tablename__ = "source_object_attribute"
176+
__table_args__ = {"schema": "process_tracker"}
177+
178+
source_object_attribute_id = Column(
179+
Integer,
180+
Sequence(
181+
"source_object_attribute_source_object_attribute_id_seq",
182+
schema="process_tracker",
183+
),
184+
primary_key=True,
185+
nullable=False,
186+
)
187+
source_object_attribute_name = Column(String(250), nullable=False)
188+
source_object_id = Column(
189+
Integer,
190+
ForeignKey("process_tracker.source_object_lkup.source_object_id"),
191+
nullable=False,
192+
)
193+
attribute_path = Column(String(750), nullable=True)
194+
data_type_id = Column(
195+
Integer,
196+
ForeignKey("process_tracker.data_type_lkup.data_type_id"),
197+
nullable=True,
198+
)
199+
data_length = Column(Integer, nullable=True)
200+
data_decimal = Column(Integer, nullable=True)
201+
is_pii = Column(Boolean, nullable=False, default=False)
202+
default_value_string = Column(String(250), nullable=True)
203+
default_value_number = Column(Numeric, nullable=True)
204+
205+
UniqueConstraint(source_object_id, source_object_attribute_name)
206+
207+
def __repr__(self):
208+
209+
return "<Source Object Attribute id=%s, name=%s, source_object=%s>" % (
210+
self.source_object_attribute_id,
211+
self.source_object_attribute_name,
212+
self.source_object_id,
213+
)
214+
215+
146216
class SourceObjectDatasetType(Base):
147217

148218
__tablename__ = "source_object_dataset_type"

0 commit comments

Comments
 (0)