Semprini / pyMDG

UML Model Driven Generation of schema, code, data and documentation.
Other
21 stars 10 forks source link

Key mapping #88

Closed Semprini closed 1 month ago

Semprini commented 3 months ago
from django.utils.translation import gettext_lazy as _
from django.db import models

class AuditableModel(models.Model):
    last_updated_by = models.CharField( max_length=50 )
    last_updated_datetime = models.DateTimeField(auto_now=True)
    created_by = models.CharField( max_length=50 )
    created_datetime = models.DateTimeField(auto_now_add=True)
    source_transation_timestamp = models.DateTimeField()
    is_deleted = models.BooleanField()

    class Meta: 
        abstract = True

class ENUM_TopicType(models.TextChoices):
    Raw = 'Raw', _('Raw')
    In_Canonical = 'In-Canonical', _('In-Canonical')

class ENUM_SourceIdentifierType(models.TextChoices):
    Column = 'Column', _('Column')
    Field = 'Field', _('Field')

class ENUM_ObjectType(models.TextChoices):
    Table = 'Table', _('Table')
    File = 'File', _('File')

class ENUM_DMLAction(models.TextChoices):
    Insert = 'Insert', _('Insert')
    Update = 'Update', _('Update')
    Delete = 'Delete', _('Delete')

class DataProduct2TopicMapping( models.Model ):
    data_product_2_topic_mapping_id = models.AutoField( primary_key=True,  )

    source_2_data_product_mapping = models.ForeignKey( 'KeyMapping.Source2DataProductMapping', related_name='data_source_2_topic_mappings', on_delete=models.CASCADE, blank=True, null=True )
    transport_topic = models.ForeignKey( 'KeyMapping.TransportTopic', related_name='data_product_2_topic_mappings', on_delete=models.CASCADE, blank=True, null=True )

    class Meta():
        db_table = 'DataProduct2TopicMapping'

        constraints = [
                models.UniqueConstraint(fields=['source_2_data_product_mapping','transport_topic',], name='unique data_product_2_topic_mapping_source_2_data_product_mapping__transport_topic__')
            ]

class DataProductKeyColumn( models.Model ):
    column_name = models.CharField( blank=True, null=True, max_length=50 )

    data_product_key_column_id = models.AutoField( primary_key=True,  )

    table_name = models.CharField( blank=True, null=True, max_length=50 )

    class Meta():
        db_table = 'DataProductKeyColumn'

        constraints = [
                models.UniqueConstraint(fields=['column_name','table_name',], name='unique data_product_key_column_column_name__table_name__')
            ]

class Source2DataProductMapping( models.Model ):
    source_2_data_product_mapping_id = models.AutoField( primary_key=True,  )

    data_product_value = models.IntegerField( blank=True, null=True,  )

    data_product_key_column = models.ForeignKey( 'KeyMapping.DataProductKeyColumn', related_name='source_2_data_product_mappings', on_delete=models.CASCADE, blank=True, null=True )
    source_key_instance = models.ForeignKey( 'KeyMapping.SourceKeyInstance', related_name='source_2_data_product_mappings', on_delete=models.CASCADE, blank=True, null=True )

    class Meta():
        db_table = 'Source2DataProductMapping'

        constraints = [
                models.UniqueConstraint(fields=['data_product_key_column','source_key_instance',], name='unique source_2_data_product_mapping_data_product_key_column__source_key_instance__')
            ]

class TransportTopic( models.Model ):
    dml_action = models.CharField( max_length=100, choices=ENUM_DMLAction.choices, blank=True, null=True )
    sequence = models.IntegerField( blank=True, null=True,  )

    topic_type = models.CharField( max_length=100, choices=ENUM_TopicType.choices, blank=True, null=True )
    source_object = models.CharField( blank=True, null=True, max_length=50 )

    dml_updated_by = models.CharField( blank=True, null=True, max_length=50 )

    partition = models.CharField( blank=True, null=True, max_length=50 )

    name = models.CharField( blank=True, null=True, max_length=50 )

    offset = models.CharField( blank=True, null=True, max_length=50 )

    source_dml_timestamp = models.DateTimeField( blank=True, null=True,  )

    topic_create_timestamp = models.DateTimeField( blank=True, null=True,  )

    correlation_id = models.IntegerField( blank=True, null=True,  )

    transport_topic_id = models.AutoField( primary_key=True,  )

    source = models.CharField( blank=True, null=True, max_length=50 )

    source_key_instance = models.ForeignKey( 'KeyMapping.SourceKeyInstance', related_name='transport_topics', on_delete=models.CASCADE, blank=True, null=True )

    class Meta():
        db_table = 'TransportTopic'

        constraints = [
                models.UniqueConstraint(fields=['topic_type','partition','name','offset','topic_create_timestamp',], name='unique transport_topic_topic_type__partition__name__offset__topic_create_timestamp__')
            ]

class SourceIdentifierValue( models.Model ):
    source_name = models.CharField( blank=True, null=True, max_length=50 )

    source_identifier_value_id = models.AutoField( primary_key=True,  )

    object_type = models.CharField( max_length=100, choices=ENUM_ObjectType.choices, blank=True, null=True )
    identifier_type = models.CharField( max_length=100, choices=ENUM_SourceIdentifierType.choices, blank=True, null=True )
    object_schema = models.CharField( blank=True, null=True, max_length=50 )

    identifier_name = models.CharField( blank=True, null=True, max_length=50 )

    identifier_value = models.CharField( blank=True, null=True, max_length=255 )

    object_name = models.CharField( blank=True, null=True, max_length=50 )

    source_key_instance = models.ForeignKey( 'KeyMapping.SourceKeyInstance', related_name='source_identifier_values', on_delete=models.CASCADE, blank=True, null=True )

    class Meta():
        db_table = 'SourceIdentifierValue'

        constraints = [
                models.UniqueConstraint(fields=['source_key_instance',], name='unique source_identifier_value_source_key_instance__')
            ]

class SourceKeyInstance( models.Model ):
    source_key_instance_id = models.AutoField( primary_key=True,  )

    create_timestamp = models.DateTimeField( blank=True, null=True,  )

    class Meta():
        db_table = 'SourceKeyInstance'