Stage related multiples Sources
- When the entities are in different databases, the data source for each entity must be specified in the stage configuration.
- This is done through the "condition" property, which is an expression that is evaluated for each entity and if true, the specified data source is used.
- Source conditions are evaluated in the order they are found in the stage, so if an entity meets the two-source condition, the data source from the first source that meets the condition will be used.
Stage related to multiple Sources sharing the mapping
This schema has two entities that are in different databases.
The database attribute is used in the entity to be able to specify that an entity is in a database other than the default of the schema.
domain:
entities:
- name: Countries
primaryKey: ["iso3"]
uniqueKey: ["name"]
properties:
- name: name
required: true
- name: iso3
length: 3
required: true
relations:
- name: states
type: manyToOne
composite: true
from: iso3
entity: States
to: countryCode
- name: States
primaryKey: ["id"]
uniqueKey: ["countryCode", "name"]
properties:
- name: id
type: integer
required: true
- name: name
required: true
- name: countryCode
required: true
length: 3
relations:
- name: country
from: countryCode
entity: Countries
to: iso3
infrastructure:
sources:
- name: dataSource1
dialect: MySQL
connection:
host: localhost
port: 3306
user: test
password: test
database: test
- name: dataSource2
dialect: PostgreSQL
connection:
host: localhost
port: 5432
user: test
password: test
database: test
stages:
- name: stage1
sources:
- name: dataSource2
condition: entity == "States"
- name: dataSource1
Environment Variables:
CNN_MYSQL={"host":"localhost","port":3306,"user":"test","password":"test","database":"test"}
CNN_POSTGRES={"host":"0.0.0.0","port":5433,"user":"test","password":"test","database":"test"}
Stage related to multiple datasources with different mapping
This example poses a stage where two sources are accessed. Data source 1 is mysql and contains the Countries table and source 2 is Postgres contains the States table.
In the case of the Countries entity, both the name of the table and the fields coincide with the name of the entity and the name of the properties, so the mapping is transparent.
But in the case of the States entity, the name of the table and its fields differ, so the mapping defines the mapping.
domain:
entities:
- name: Positions
abstract: true
properties:
- name: latitude
length: 16
- name: longitude
length: 16
- name: Countries
extends: Positions
primaryKey: ["iso3"]
uniqueKey: ["name"]
properties:
- name: name
required: true
- name: iso3
length: 3
required: true
- name: region
- name: subregion
relations:
- name: states
type: manyToOne
composite: true
from: iso3
entity: States
to: countryCode
- name: States
extends: Positions
primaryKey: ["id"]
uniqueKey: ["countryCode", "name"]
properties:
- name: id
type: integer
required: true
- name: name
required: true
- name: countryCode
required: true
length: 3
relations:
- name: country
from: countryCode
entity: Countries
to: iso3
infrastructure:
mappings:
- name: mapping1
- name: mapping2
entities:
- name: States
mapping: TBL_STATES
properties:
- name: id
mapping: ID
- name: name
mapping: NAME
- name: countryCode
mapping: COUNTRY_CODE
- name: latitude
mapping: LATITUDE
- name: longitude
mapping: LONGITUDE
sources:
- name: dataSource1
dialect: MySQL
mapping: mapping1
connection: $CNN_MYSQL
- name: dataSource2
dialect: PostgreSQL
mapping: mapping2
connection: $CNN_POSTGRES
stages:
- name: stage1
sources:
- name: dataSource2
condition: entity == "States"
- name: dataSource1