mirror of
https://gitlab.com/cief-data/dbt_cloud.git
synced 2026-08-19 04:14:00 +00:00
DBT structure change
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
{% docs src_crisp_api %}
|
||||
|
||||
Application link: https://crisp.chat/en/
|
||||
|
||||
Data is extract from [CRISP Api Python Library](https://github.com/crisp-im/python-crisp-api), using custom python code.
|
||||
|
||||
The API Token will refresh everyday, we can know our usage from [CRISP Marketplace](https://marketplace.crisp.chat/plugins/). 1 Token will used when 1 API is call.
|
||||
|
||||
- When the python get the JSON data. It will denormalize it.
|
||||
|
||||
Input:
|
||||
|
||||
"data": [
|
||||
{
|
||||
"people_id": "aaaa-bbbb-cccc",
|
||||
|
||||
"email": "tesing@gmail.com",
|
||||
|
||||
"person": {
|
||||
"gender": "male"
|
||||
}
|
||||
}]
|
||||
|
||||
|
||||
Output:
|
||||
|
||||
|people_id|email|person__gender|
|
||||
|----|----|----|
|
||||
|aaaa-bbbb-cccc|tesing@gmail.com|male|
|
||||
|
||||
- `api_called_at` will add into the raw data when extract. _It should added an underscore but YAM forget_
|
||||
|
||||
- Python will call the API in everyday 12:30AM
|
||||
|
||||
- The raw data will use copy into snowflake in 2AM everyday
|
||||
|
||||
- Depend on target.name to determin which snowflake raw schema
|
||||
|
||||
```JINJA
|
||||
{_%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{_%- else -%} DEV_CIEF_RAW_DB
|
||||
{_%- endif -%}
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
@@ -0,0 +1,85 @@
|
||||
version: 2
|
||||
|
||||
sources:
|
||||
- name: src_crisp_api
|
||||
description: '{{ doc("src_crisp_api") }}'
|
||||
database: |
|
||||
{%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{%- else -%} DEV_CIEF_RAW_DB
|
||||
{%- endif -%}
|
||||
schema: CRISP_API
|
||||
loader: custom_python_code
|
||||
loaded_at_field: api_called_at
|
||||
freshness:
|
||||
warn_after: {count: 26, period: hour}
|
||||
error_after: {count: 48, period: hour}
|
||||
meta:
|
||||
owner: "@yam"
|
||||
model_maturity: prod
|
||||
tags:
|
||||
- crisp
|
||||
- daily
|
||||
|
||||
|
||||
tables:
|
||||
- name: get_message_in_conversations
|
||||
description: Table that get all the message the send by user/operator
|
||||
columns:
|
||||
- name: fingerprint
|
||||
description: Primary key for 'get_message_in_conversations'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: delivered
|
||||
description: the platform which after the message is output from origin, and delivered to the user/operator. When an operator send a message but the user is not online anymore, we send it via email only after 2min during these 2min, delivered is empty
|
||||
|
||||
|
||||
- name: get_people_data
|
||||
description: This is CIEF created custom field, when the user is chat with us using FB/Whatsapp/ExchangeWebsite/ShippingWebsite our crisp will auto mapping user login account & some identity information
|
||||
columns:
|
||||
- name: people_id
|
||||
description: Primary key for 'get_people_data'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: get_people_subscription_status
|
||||
description: SCD-Type1. The CRISP email subscription status. If we mapping the user_created_datetime and email_unsubscripte_datetime we will know when the unsubscripte duration
|
||||
columns:
|
||||
- name: people_id
|
||||
description: Primary key for 'get_people_subscription_status'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: list_conversations
|
||||
description: SCD-Type1. All the chat box in the CRISP. One user might have different chat box.
|
||||
columns:
|
||||
- name: session_id
|
||||
description: Primary key for 'list_conversations'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: list_people_profiles
|
||||
description: SCD-Type1. The user profile, combination of user & company data.
|
||||
columns:
|
||||
- name: people_id
|
||||
description: Primary key for 'list_people_profiles'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: list_website_operator
|
||||
description: SCD-Type1. CIEF Crisp Admin/Agent table
|
||||
columns:
|
||||
- name: details__user_id
|
||||
description: Primary key for 'list_website_operator'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
@@ -0,0 +1,48 @@
|
||||
-- IMPORT
|
||||
WITH get_people_data AS (
|
||||
SELECT * FROM {{ source('src_crisp_api', 'get_people_data') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
get_people_data_rename AS (
|
||||
SELECT
|
||||
people_id AS user_id,
|
||||
data__company_name AS company_name,
|
||||
data__wa_number AS whatsapp_number,
|
||||
data__whatsapp_business_number AS whatsapp_business_number,
|
||||
data__fb_page AS facebook_page_name,
|
||||
data__fb_page_id AS facebook_page_id,
|
||||
data__exchange_marking AS exchange_marking_id,
|
||||
data__izyim_marking AS izyim_marking_id,
|
||||
data__lite_marking AS lite_marking_id,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM get_people_data
|
||||
),
|
||||
|
||||
--FINAL
|
||||
final_base_crisp__get_people_data AS (
|
||||
SELECT
|
||||
-- ids
|
||||
user_id,
|
||||
exchange_marking_id,
|
||||
izyim_marking_id,
|
||||
lite_marking_id,
|
||||
facebook_page_id,
|
||||
|
||||
-- dimensions
|
||||
company_name,
|
||||
whatsapp_number,
|
||||
whatsapp_business_number,
|
||||
facebook_page_name,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM get_people_data_rename
|
||||
)
|
||||
SELECT * FROM final_base_crisp__get_people_data
|
||||
@@ -0,0 +1,41 @@
|
||||
-- IMPORT
|
||||
WITH get_people_subscription_status AS (
|
||||
SELECT * FROM {{ ref('snap_crisp__get_people_subscription_status') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
get_people_subscription_status_rename AS (
|
||||
SELECT
|
||||
dbt_scd_id AS user_email_subscription_id,
|
||||
people_id AS user_id,
|
||||
IFF(email = TRUE, 1, 0) AS is_subscribed,
|
||||
dbt_valid_from AS from_datetime,
|
||||
dbt_valid_to AS to_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM get_people_subscription_status
|
||||
),
|
||||
|
||||
--FINAL
|
||||
final_base_crisp__user_email_subscriptions AS (
|
||||
SELECT
|
||||
-- ids
|
||||
user_email_subscription_id,
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
is_subscribed,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
from_datetime,
|
||||
to_datetime,
|
||||
|
||||
-- metaadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM get_people_subscription_status_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_base_crisp__user_email_subscriptions
|
||||
@@ -0,0 +1,109 @@
|
||||
-- IMPORT
|
||||
WITH list_people_profiles AS (
|
||||
SELECT * FROM {{ source('src_crisp_api', 'list_people_profiles') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
list_people_profiles_rename AS (
|
||||
SELECT
|
||||
people_id AS user_id,
|
||||
person__nickname AS name,
|
||||
person__phone AS phone,
|
||||
email AS email,
|
||||
person__website AS website,
|
||||
score AS score,
|
||||
segments AS segments,
|
||||
person__employment__role AS role,
|
||||
person__employment__seniority AS seniority,
|
||||
person__employment__title AS title,
|
||||
person__gender AS gender,
|
||||
person__timezone AS timezone,
|
||||
person__geolocation__country AS country,
|
||||
person__geolocation__city AS city,
|
||||
person__geolocation__region AS region_code,
|
||||
person__address AS address,
|
||||
person__locales AS locales,
|
||||
person__geolocation__coordinates__latitude AS latitude,
|
||||
person__geolocation__coordinates__longitude AS longitude,
|
||||
convert_timezone('Asia/Kuala_Lumpur', active__last) AS last_activated_datetime,
|
||||
convert_timezone('Asia/Kuala_Lumpur', created_at) AS created_datetime,
|
||||
convert_timezone('Asia/Kuala_Lumpur', updated_at) AS updated_datetime,
|
||||
|
||||
company__name AS company_name,
|
||||
company__legal_name AS company_legal_name,
|
||||
company__description AS company_description,
|
||||
company__phones AS company_phone,
|
||||
company__emails AS company_emails,
|
||||
company__url AS company_website,
|
||||
company__domain AS company_domain,
|
||||
company__tags AS company_tags,
|
||||
company__metrics__employees AS company_number_of_employees,
|
||||
company__metrics__market_cap AS company_market_cap,
|
||||
company__geolocation__country AS company_country,
|
||||
company__geolocation__city AS company_city,
|
||||
company__geolocation__region AS company_region,
|
||||
company__geolocation__coordinates__latitude AS company_latitude,
|
||||
company__geolocation__coordinates__longitude AS company_logitude,
|
||||
company__timezone AS company_timezone,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM list_people_profiles
|
||||
),
|
||||
|
||||
|
||||
--FINAL
|
||||
final_base_crisp__users AS (
|
||||
SELECT
|
||||
-- ids
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
website,
|
||||
score,
|
||||
segments,
|
||||
role,
|
||||
seniority,
|
||||
title,
|
||||
gender,
|
||||
timezone,
|
||||
country,
|
||||
city,
|
||||
region_code,
|
||||
address,
|
||||
locales,
|
||||
latitude,
|
||||
longitude,
|
||||
company_name,
|
||||
company_legal_name,
|
||||
company_description,
|
||||
company_phone,
|
||||
company_emails,
|
||||
company_website,
|
||||
company_domain,
|
||||
company_tags,
|
||||
company_number_of_employees,
|
||||
company_market_cap,
|
||||
company_country,
|
||||
company_city,
|
||||
company_region,
|
||||
company_latitude,
|
||||
company_logitude,
|
||||
company_timezone,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
last_activated_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM list_people_profiles_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_base_crisp__users
|
||||
@@ -0,0 +1,46 @@
|
||||
-- IMPORT
|
||||
WITH list_conversations AS (
|
||||
SELECT * FROM {{ source('src_crisp_api', 'list_conversations') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
list_conversations_rename AS (
|
||||
SELECT
|
||||
session_id AS conversation_id,
|
||||
people_id AS user_id,
|
||||
state AS status,
|
||||
IFF(is_blocked = TRUE, 1, 0) AS is_blocked_conversation,
|
||||
assigned__user_id AS operator_id,
|
||||
convert_timezone('Asia/Kuala_Lumpur', created_at) AS conversation_created_datetime,
|
||||
convert_timezone('Asia/Kuala_Lumpur', updated_at) AS conversation_updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM list_conversations
|
||||
),
|
||||
|
||||
|
||||
--FINAL
|
||||
final_stg_crisp__conversations AS (
|
||||
SELECT
|
||||
-- ids
|
||||
conversation_id,
|
||||
user_id,
|
||||
operator_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
is_blocked_conversation,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
conversation_created_datetime,
|
||||
conversation_updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM list_conversations_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_stg_crisp__conversations
|
||||
@@ -0,0 +1,65 @@
|
||||
-- IMPORT
|
||||
WITH get_message_in_conversations AS (
|
||||
SELECT * FROM {{ source('src_crisp_api', 'get_message_in_conversations') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
get_message_in_conversations_rename AS (
|
||||
SELECT
|
||||
fingerprint AS message_id,
|
||||
session_id AS conversation_id,
|
||||
user__user_id AS user_id,
|
||||
user__nickname AS user_name,
|
||||
from_user AS message_from_side,
|
||||
origin AS message_generated_platform,
|
||||
delivered AS message_delivered_platform,
|
||||
read AS message_read_platform,
|
||||
type AS message_format,
|
||||
content__namespace AS event_type,
|
||||
content__text AS event_message,
|
||||
content AS message,
|
||||
edited AS is_edited_message,
|
||||
content__type AS attachment_type,
|
||||
content__name AS attachment_name,
|
||||
content__url AS attachment_url,
|
||||
convert_timezone('Asia/Kuala_Lumpur', timestamp) AS created_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM get_message_in_conversations
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final_stg_crisp__messages AS (
|
||||
SELECT
|
||||
-- ids
|
||||
message_id,
|
||||
conversation_id,
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
user_name,
|
||||
message_from_side,
|
||||
message_generated_platform,
|
||||
message_delivered_platform,
|
||||
message_read_platform,
|
||||
message_format,
|
||||
event_type,
|
||||
event_message,
|
||||
message,
|
||||
is_edited_message,
|
||||
attachment_type,
|
||||
attachment_name,
|
||||
attachment_url,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM get_message_in_conversations_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_stg_crisp__messages
|
||||
@@ -0,0 +1,37 @@
|
||||
-- IMPORT
|
||||
WITH list_website_operators AS (
|
||||
SELECT * FROM {{ source('src_crisp_api', 'list_website_operator') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
list_website_operators_rename AS (
|
||||
SELECT
|
||||
details__user_id AS operator_user_id,
|
||||
details__title AS title,
|
||||
details__first_name || ' ' || details__last_name AS name,
|
||||
details__email AS email,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM list_website_operators
|
||||
),
|
||||
|
||||
--FINAL
|
||||
final_stg_crisp__operators AS (
|
||||
SELECT
|
||||
-- ids
|
||||
operator_user_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
title,
|
||||
email,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM list_website_operators_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_stg_crisp__operators
|
||||
@@ -0,0 +1,149 @@
|
||||
--IMPORT
|
||||
WITH users AS (
|
||||
SELECT * FROM {{ ref('base_crisp__users') }}
|
||||
),
|
||||
|
||||
user_data AS (
|
||||
SELECT * FROM {{ ref('base_crisp__user_data') }}
|
||||
),
|
||||
|
||||
user_email_subscriptions AS (
|
||||
SELECT * FROM {{ ref('base_crisp__user_email_subscriptions') }}
|
||||
),
|
||||
|
||||
--LOGIC
|
||||
latest_user_email_subscriptions AS (
|
||||
SELECT
|
||||
*
|
||||
|
||||
FROM user_email_subscriptions
|
||||
|
||||
WHERE
|
||||
to_datetime IS NULL
|
||||
),
|
||||
|
||||
people_get_marking_id_and_email_subscriptions AS (
|
||||
SELECT
|
||||
users.user_id,
|
||||
users.name,
|
||||
users.phone,
|
||||
users.email,
|
||||
users.website,
|
||||
users.score,
|
||||
users.segments,
|
||||
users.role,
|
||||
users.seniority,
|
||||
users.title,
|
||||
users.gender,
|
||||
users.timezone,
|
||||
users.country,
|
||||
users.city,
|
||||
users.region_code,
|
||||
users.address,
|
||||
users.locales,
|
||||
users.latitude,
|
||||
users.longitude,
|
||||
users.last_activated_datetime,
|
||||
users.created_datetime,
|
||||
users.updated_datetime,
|
||||
users.company_name,
|
||||
users.company_legal_name,
|
||||
users.company_description,
|
||||
users.company_phone,
|
||||
users.company_emails,
|
||||
users.company_website,
|
||||
users.company_domain,
|
||||
users.company_tags,
|
||||
users.company_number_of_employees,
|
||||
users.company_market_cap,
|
||||
users.company_country,
|
||||
users.company_city,
|
||||
users.company_region,
|
||||
users.company_latitude,
|
||||
users.company_logitude,
|
||||
users.company_timezone,
|
||||
user_data.company_name AS marking_company_name,
|
||||
user_data.whatsapp_number,
|
||||
user_data.whatsapp_business_number,
|
||||
user_data.facebook_page_name,
|
||||
user_data.facebook_page_id,
|
||||
user_data.exchange_marking_id,
|
||||
user_data.izyim_marking_id,
|
||||
user_data.lite_marking_id,
|
||||
latest_user_email_subscriptions.is_subscribed,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM users
|
||||
|
||||
LEFT JOIN user_data
|
||||
ON (users.user_id = user_data.user_id)
|
||||
|
||||
LEFT JOIN latest_user_email_subscriptions
|
||||
ON (users.user_id = latest_user_email_subscriptions.user_id)
|
||||
),
|
||||
|
||||
--FINAL
|
||||
final_base_crisp__user_email_subscriptions AS (
|
||||
SELECT
|
||||
-- ids
|
||||
user_id,
|
||||
exchange_marking_id,
|
||||
izyim_marking_id,
|
||||
lite_marking_id,
|
||||
facebook_page_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
phone,
|
||||
email,
|
||||
website,
|
||||
score,
|
||||
segments,
|
||||
role,
|
||||
seniority,
|
||||
title,
|
||||
gender,
|
||||
timezone,
|
||||
country,
|
||||
city,
|
||||
region_code,
|
||||
address,
|
||||
locales,
|
||||
latitude,
|
||||
longitude,
|
||||
company_name,
|
||||
company_legal_name,
|
||||
company_description,
|
||||
company_phone,
|
||||
company_emails,
|
||||
company_website,
|
||||
company_domain,
|
||||
company_tags,
|
||||
company_number_of_employees,
|
||||
company_market_cap,
|
||||
company_country,
|
||||
company_city,
|
||||
company_region,
|
||||
company_latitude,
|
||||
company_logitude,
|
||||
company_timezone,
|
||||
marking_company_name,
|
||||
whatsapp_number,
|
||||
whatsapp_business_number,
|
||||
facebook_page_name,
|
||||
is_subscribed,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
last_activated_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM people_get_marking_id_and_email_subscriptions
|
||||
)
|
||||
|
||||
SELECT * FROM final_base_crisp__user_email_subscriptions
|
||||
@@ -0,0 +1,21 @@
|
||||
{% docs src_exchange_mysql %}
|
||||
|
||||
Application link: https://exchange.cief-malaysia.com/
|
||||
|
||||
Data is extract from CIEF Selfhost MYSQL `exchange_production`, using custom python code.
|
||||
|
||||
- `_source_loaded_at` will add into the raw data when extract
|
||||
|
||||
- Python will run the SQL in everyday 12:30AM
|
||||
|
||||
- The raw data will use copy into snowflake in 2AM everyday
|
||||
|
||||
- Depend on target.name to determin which snowflake raw schema
|
||||
|
||||
```JINJA
|
||||
{_%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{_%- else -%} DEV_CIEF_RAW_DB
|
||||
{_%- endif -%}
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
@@ -0,0 +1,26 @@
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: stg_exchange__activity_logs
|
||||
description: exchange user activity logs
|
||||
|
||||
- name: stg_exchange__banks
|
||||
description: user input bank information, and be bank transfer / alipay / personol bank information
|
||||
|
||||
- name: stg_exchange__booking_logs
|
||||
description: Full picture of booking logs with current & archived data
|
||||
|
||||
- name: stg_exchange__bookings
|
||||
description: SCD-Type1 bookings data
|
||||
|
||||
- name: stg_exchange__companies
|
||||
description: Company that register in Exchange system, contain client/supplier company
|
||||
|
||||
- name: stg_exchange__companies_brg_segments
|
||||
description: Bridge between `companies` and `segments`
|
||||
|
||||
- name: stg_exchange__companies_brg_users
|
||||
description: Bridge between `companies` and `users`
|
||||
|
||||
- name: stg_exchange__company_addresses
|
||||
description: Company addresses that input when register
|
||||
@@ -0,0 +1,618 @@
|
||||
version: 2
|
||||
|
||||
sources:
|
||||
- name: src_exchange_mysql
|
||||
description: '{{ doc("src_exchange_mysql") }}'
|
||||
database: |
|
||||
{%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{%- else -%} DEV_CIEF_RAW_DB
|
||||
{%- endif -%}
|
||||
schema: EXCHANGE_MYSQL
|
||||
loader: custom_python_code
|
||||
loaded_at_field: _source_loaded_datetime
|
||||
freshness:
|
||||
warn_after: {count: 26, period: hour}
|
||||
error_after: {count: 48, period: hour}
|
||||
meta:
|
||||
owner: "@yam"
|
||||
model_maturity: prod
|
||||
tags:
|
||||
- exchange
|
||||
- daily
|
||||
|
||||
|
||||
tables:
|
||||
- name: activity_log
|
||||
description: Contains most table's activity log that CUD (created, updated, deleted) in www.exchange.cief-malaysia.com
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'activity_log'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: description
|
||||
description: system CUD activity list down
|
||||
tests:
|
||||
- accepted_values:
|
||||
values: ['created', 'updated', 'deleted']
|
||||
|
||||
- name: subject_id
|
||||
description: The exchange CUD table's id, need to refer subject_type column to know what table is CUD in the row
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: subject_type
|
||||
description: What table that CUD using in the row
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: causer_id
|
||||
description: Need to refer causer_type column to know who is CUD in the row. it is not well maintain there is some NULL
|
||||
|
||||
- name: causer_type
|
||||
description: Who is CUD the row
|
||||
|
||||
- name: properties
|
||||
description: Json data format that contain attributes of the activity, it is not well maintain, subject (Country, ServiceType, CurrencyRate. UserEmailVerification, File) have properties only
|
||||
|
||||
- name: created_at
|
||||
description: Datetime that CUD activity occur
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: updated_at
|
||||
description: Exactly same with created_at, redundant column
|
||||
|
||||
tests:
|
||||
- dbt_expectations.expect_column_pair_values_to_be_equal:
|
||||
column_A: updated_at
|
||||
column_B: created_at
|
||||
|
||||
|
||||
- name: addresses
|
||||
description: Addresses that input when user register
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'addresses'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: company_id
|
||||
description: Foreign keys for 'companies'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: country_id
|
||||
description: Foreign keys for 'countries'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: state_id
|
||||
description: Foreign keys for 'states'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: district_id
|
||||
description: Foreign keys for 'districts'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: postcode
|
||||
description: The number/string that user input
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_of_type:
|
||||
column_type: integer
|
||||
|
||||
- name: street_one
|
||||
description: The string that user input
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: street_two
|
||||
description: The string that user input
|
||||
|
||||
- name: billing
|
||||
description: If mark 1 means it is billing address, 0 means is not billing address, every company should have 1 billing address
|
||||
tests:
|
||||
- dbt_expectations.expect_column_max_to_be_between: #Every company should have a billing address
|
||||
min_value: 1
|
||||
max_value: 1
|
||||
group_by: [company_id]
|
||||
- dbt_expectations.expect_column_sum_to_be_between: #1 company should have 1 billing address only
|
||||
min_value: 1
|
||||
max_value: 1
|
||||
group_by: [company_id]
|
||||
row_condition: "deleted_at is null"
|
||||
|
||||
- name: deleted_at
|
||||
description: System generate datetime that address was deleted
|
||||
|
||||
- name: created_at
|
||||
description: System generate datetime that address was created
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: updated_at
|
||||
description: System generate datetime that address was updated
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
- name: announcement_segment
|
||||
description: Superadmin / Operator guys will segment the announcment, but normally they will leave it default. 2 FK combine to becoem a relation table.
|
||||
columns:
|
||||
- name: announcement_id
|
||||
description: Primary key for 'announcement_segment' & Foreign key for 'announcements'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: segment_id
|
||||
description: Primary key for 'announcement_segment' & Foreign key for 'segments'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: created_at
|
||||
description: Abandon column
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_null
|
||||
|
||||
- name: updated_at
|
||||
description: Abandon column
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_null
|
||||
|
||||
|
||||
- name: announcements
|
||||
description: Announcements that show in our website which create by superadmin
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'announcements'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: title
|
||||
description: title of announcement, using string
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: description
|
||||
description: description of announcement, using longtext, have <br> html for break
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: starting_on
|
||||
description: announcement starting datetime
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: ending_on
|
||||
description: announcement ending datetime
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: is_all_day
|
||||
description: column might not in use, system auto generate
|
||||
tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values: [0]
|
||||
|
||||
- name: duration
|
||||
description: column might not in use, system auto generate
|
||||
tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values: [0]
|
||||
|
||||
- name: is_recurring
|
||||
description: column might not in use, system auto generate
|
||||
tests:
|
||||
- not_null
|
||||
- accepted_values:
|
||||
values: [0]
|
||||
|
||||
- name: recurrence_pattern
|
||||
description: column might not in use, system auto generate
|
||||
tests:
|
||||
- dbt_expectations.expect_column_values_to_be_null
|
||||
|
||||
- name: deleted_at
|
||||
description: system generate datetime that announcment was deleted
|
||||
|
||||
- name: created_at
|
||||
description: system generate datetime that announcment was created
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: updated_at
|
||||
description: system generate datetime that announcment was updated
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
- name: bank_logs
|
||||
description: Abandon table
|
||||
config:
|
||||
enabled: false
|
||||
|
||||
|
||||
- name: banks
|
||||
description: Table which store banks details.
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'banks'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
- name: company_id
|
||||
description: Foreign keys for 'companies'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: reference
|
||||
description: A string which write by user/company for the bank transfer reference or other remind ussage
|
||||
|
||||
- name: holder_name
|
||||
description: Bank holder name
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: account_no
|
||||
description: Bank account number
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
|
||||
|
||||
- name: booking_logs
|
||||
description: Raw `bookings` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'booking_logs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: bookings
|
||||
description: Raw `bookings` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'bookings'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: companies
|
||||
description: Raw `companies` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'companies'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: contacts
|
||||
description: Raw `contacts` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'contacts'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: countries
|
||||
description: Raw `countries` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'countries'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: currencies
|
||||
description: Raw `currencies` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'currencies'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: currency_logs
|
||||
description: Raw `currency_logs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'currency_logs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: currency_rate_logs
|
||||
description: Raw `currency_rate_logs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'currency_rate_logs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: currency_rates
|
||||
description: Raw `currency_rates` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'currency_rates'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: districts
|
||||
description: Raw `districts` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'districts'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: documents
|
||||
description: Raw `documents` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'documents'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: employees
|
||||
description: Raw `employees` table from Snowflake
|
||||
columns:
|
||||
- name: company_id
|
||||
description: Primary key for 'employees'
|
||||
|
||||
|
||||
- name: failed_jobs
|
||||
description: Raw `failed_jobs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'failed_jobs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: files
|
||||
description: Raw `files` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'files'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: group_transactions
|
||||
description: Raw `group_transactions` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'group_transactions'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: groups
|
||||
description: Raw `groups` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'groups'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: jobs
|
||||
description: Raw `jobs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'jobs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: migrations
|
||||
description: Raw `migrations` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'migrations'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: model_has_roles
|
||||
description: Raw `model_has_roles` table from Snowflake
|
||||
columns:
|
||||
- name: role_id
|
||||
description: Primary key for 'model_has_roles'
|
||||
|
||||
|
||||
- name: notifications
|
||||
description: Raw `notifications` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'notifications'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: password_resets
|
||||
description: Raw `password_resets` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'password_resets'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: permissions
|
||||
description: Raw `permissions` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'permissions'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: role_has_permissions
|
||||
description: Raw `role_has_permissions` table from Snowflake
|
||||
columns:
|
||||
- name: permission_id
|
||||
description: Primary key for 'role_has_permissions'
|
||||
|
||||
|
||||
- name: roles
|
||||
description: Raw `roles` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'roles'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: segment_companies
|
||||
description: Raw `segment_companies` table from Snowflake
|
||||
columns:
|
||||
- name: segment_id
|
||||
description: Primary key for 'segment_companies'
|
||||
|
||||
|
||||
- name: segment_constants
|
||||
description: Raw `segment_constants` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'segment_constants'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: segments
|
||||
description: Raw `segments` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'segments'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: service_types
|
||||
description: Raw `service_types` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'service_types'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: states
|
||||
description: Raw `states` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'states'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transaction_detail
|
||||
description: Raw `transaction_detail` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transaction_detail'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transaction_logs
|
||||
description: Raw `transaction_logs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transaction_logs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transactions
|
||||
description: Raw `transactions` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transactions'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: user_email_verifications
|
||||
description: Raw `user_email_verifications` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'user_email_verifications'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: users
|
||||
description: Raw `users` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'users'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: wallet_logs
|
||||
description: Raw `wallet_logs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'wallet_logs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: wallets
|
||||
description: Raw `wallets` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'wallets'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
@@ -0,0 +1,54 @@
|
||||
-- IMPORTS
|
||||
WITH activity_logs AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'activity_log') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
activity_logs_rename AS (
|
||||
|
||||
SELECT
|
||||
activity_logs.id AS activity_log_id,
|
||||
activity_logs.log_name,
|
||||
activity_logs.description,
|
||||
activity_logs.subject_id,
|
||||
activity_logs.subject_type,
|
||||
activity_logs.causer_id,
|
||||
activity_logs.causer_type,
|
||||
activity_logs.properties,
|
||||
activity_logs.created_at AS created_datetime,
|
||||
activity_logs.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM activity_logs
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__activity_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
activity_log_id,
|
||||
subject_id,
|
||||
causer_id,
|
||||
|
||||
-- dimensions
|
||||
log_name,
|
||||
description,
|
||||
subject_type,
|
||||
causer_type,
|
||||
properties,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM activity_logs_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__activity_logs
|
||||
@@ -0,0 +1,64 @@
|
||||
-- IMPORTS
|
||||
WITH banks AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'banks') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
banks_rename AS (
|
||||
|
||||
SELECT
|
||||
banks.id AS bank_id,
|
||||
banks.company_id,
|
||||
banks.reference AS recipient_reference,
|
||||
banks.bank_name,
|
||||
banks.holder_name,
|
||||
banks.account_no AS account_number,
|
||||
banks.bank_branch,
|
||||
banks.swift AS swift_code,
|
||||
banks.snap AS cnaps_code,
|
||||
banks.type AS bank_type,
|
||||
banks.default AS is_default,
|
||||
banks.status,
|
||||
banks.country_id,
|
||||
banks.deleted_at AS deleted_datetime,
|
||||
banks.created_at AS created_datetime,
|
||||
banks.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM banks
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__banks AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
bank_id,
|
||||
company_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
bank_type,
|
||||
is_default,
|
||||
account_number,
|
||||
bank_name,
|
||||
bank_branch,
|
||||
holder_name,
|
||||
swift_code,
|
||||
cnaps_code,
|
||||
recipient_reference,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM banks_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__banks
|
||||
@@ -0,0 +1,63 @@
|
||||
-- IMPORTS
|
||||
WITH booking_arch_logs AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'booking_logs') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
booking_arch_logs_rename AS (
|
||||
|
||||
SELECT
|
||||
booking_arch_logs.id AS booking_log_id,
|
||||
booking_arch_logs.booking_id,
|
||||
booking_arch_logs.company_id,
|
||||
booking_arch_logs.marking AS booking_marking_id,
|
||||
booking_arch_logs.service_id AS service_type,
|
||||
booking_arch_logs.bank_id,
|
||||
booking_arch_logs.fix_amount AS fix_value,
|
||||
booking_arch_logs.fix_currency_id,
|
||||
booking_arch_logs.convertible_currency_id AS quote_currency_id,
|
||||
booking_arch_logs.conversion_currency_id AS base_currency_id,
|
||||
booking_arch_logs.status,
|
||||
booking_arch_logs.deleted_at AS deleted_datetime,
|
||||
booking_arch_logs.created_at AS created_datetime,
|
||||
booking_arch_logs.updated_at As updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM booking_arch_logs
|
||||
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final_base_exchange__booking_arch_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
booking_log_id,
|
||||
booking_id,
|
||||
booking_marking_id,
|
||||
company_id,
|
||||
bank_id,
|
||||
fix_currency_id,
|
||||
quote_currency_id,
|
||||
base_currency_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
service_type,
|
||||
|
||||
-- measures
|
||||
fix_value,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM booking_arch_logs_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_base_exchange__booking_arch_logs
|
||||
@@ -0,0 +1,61 @@
|
||||
-- IMPORTS
|
||||
WITH bookings AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'bookings') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
bookings_rename AS (
|
||||
|
||||
SELECT
|
||||
bookings.id AS booking_id,
|
||||
bookings.company_id,
|
||||
bookings.marking AS booking_marking_id,
|
||||
bookings.service_id AS service_type,
|
||||
bookings.bank_id,
|
||||
bookings.fix_amount AS fix_value,
|
||||
bookings.fix_currency_id,
|
||||
bookings.convertible_currency_id AS quote_currency_id,
|
||||
bookings.conversion_currency_id AS base_currency_id,
|
||||
bookings.status,
|
||||
bookings.deleted_at AS deleted_datetime,
|
||||
bookings.created_at AS created_datetime,
|
||||
bookings.updated_at As updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM bookings
|
||||
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final_base_exchange__bookings AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
booking_id,
|
||||
booking_marking_id,
|
||||
company_id,
|
||||
bank_id,
|
||||
fix_currency_id,
|
||||
quote_currency_id,
|
||||
base_currency_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
service_type,
|
||||
|
||||
-- measures
|
||||
fix_value,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM bookings_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final_base_exchange__bookings
|
||||
@@ -0,0 +1,54 @@
|
||||
-- IMPORTS
|
||||
WITH companies AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'companies') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
companies_column_rename AS (
|
||||
|
||||
SELECT
|
||||
companies.id AS company_id,
|
||||
companies.name,
|
||||
companies.reference AS company_marking_id,
|
||||
companies.debtor AS autocount_id,
|
||||
companies.type AS company_type,
|
||||
companies.business_type,
|
||||
companies.status,
|
||||
companies.deleted_at AS deleted_datetime,
|
||||
companies.created_at AS created_datetime,
|
||||
companies.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM companies
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__companies AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
company_id,
|
||||
company_marking_id,
|
||||
autocount_id,
|
||||
|
||||
-- dimension
|
||||
name,
|
||||
company_type,
|
||||
business_type,
|
||||
status,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM companies_column_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__companies
|
||||
@@ -0,0 +1,43 @@
|
||||
-- IMPORTS
|
||||
WITH snap_segment_companies AS (
|
||||
SELECT * FROM {{ ref('snap_exchange__segment_companies') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
segment_companies_rename AS (
|
||||
|
||||
SELECT
|
||||
snap_segment_companies.segment_id,
|
||||
snap_segment_companies.company_id,
|
||||
snap_segment_companies.dbt_valid_from AS dbt_valid_from_datetime,
|
||||
snap_segment_companies.dbt_valid_to AS dbt_valid_to_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM snap_segment_companies
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__companies_brg_segments AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
segment_id,
|
||||
company_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
dbt_valid_from_datetime,
|
||||
dbt_valid_to_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM segment_companies_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__companies_brg_segments
|
||||
@@ -0,0 +1,81 @@
|
||||
-- IMPORTS
|
||||
WITH addresses AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'addresses') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
addresses_rename AS (
|
||||
|
||||
SELECT
|
||||
addresses.id AS company_address_id,
|
||||
addresses.company_id,
|
||||
addresses.country_id,
|
||||
addresses.state_id,
|
||||
addresses.district_id,
|
||||
addresses.postcode,
|
||||
addresses.street_one AS address_line_one,
|
||||
addresses.street_two AS address_line_two,
|
||||
addresses.billing AS is_billing_address,
|
||||
addresses.deleted_at AS deleted_datetime,
|
||||
addresses.created_at AS created_datetime,
|
||||
addresses.updated_At AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM addresses
|
||||
),
|
||||
|
||||
remove_deleted_addresses AS (
|
||||
SELECT
|
||||
*
|
||||
|
||||
FROM addresses_rename
|
||||
|
||||
WHERE
|
||||
deleted_datetime IS NULL
|
||||
),
|
||||
|
||||
lastest_billing_and_non_billing_addresses AS (
|
||||
SELECT
|
||||
*,
|
||||
-- 1 will be latest updated address, rank by updated_at date
|
||||
row_number() OVER
|
||||
(PARTITION BY remove_deleted_addresses.company_id, remove_deleted_addresses.is_billing_address
|
||||
ORDER BY remove_deleted_addresses.updated_datetime DESC) AS lastest_address_rank
|
||||
|
||||
FROM remove_deleted_addresses
|
||||
|
||||
QUALIFY
|
||||
lastest_address_rank = 1
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__company_addresses AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
company_address_id,
|
||||
company_id,
|
||||
country_id,
|
||||
state_id,
|
||||
district_id,
|
||||
|
||||
-- dimensions
|
||||
postcode,
|
||||
address_line_one,
|
||||
address_line_two,
|
||||
is_billing_address,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM lastest_billing_and_non_billing_addresses
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__company_addresses
|
||||
@@ -0,0 +1,68 @@
|
||||
-- IMPORTS
|
||||
WITH contacts AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'contacts') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
contacts_rename AS (
|
||||
|
||||
SELECT
|
||||
contacts.id AS contact_id,
|
||||
contacts.company_id,
|
||||
contacts.country_id,
|
||||
contacts.reference AS contact_name,
|
||||
contacts.phone,
|
||||
contacts.email,
|
||||
contacts.wechat_id AS wechat,
|
||||
contacts.deleted_at AS deleted_datetime,
|
||||
contacts.created_at AS created_datetime,
|
||||
contacts.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM contacts
|
||||
),
|
||||
|
||||
get_latest_company_contacts AS (
|
||||
SELECT
|
||||
*,
|
||||
row_number() OVER
|
||||
(PARTITION BY company_id
|
||||
ORDER BY created_datetime DESC) AS last_row_number
|
||||
|
||||
FROM contacts_rename
|
||||
|
||||
QUALIFY
|
||||
last_row_number = 1
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__company_contacts AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
contact_id,
|
||||
company_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
contact_name,
|
||||
phone,
|
||||
email,
|
||||
wechat,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM get_latest_company_contacts
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__company_contacts
|
||||
@@ -0,0 +1,50 @@
|
||||
-- IMPORTS
|
||||
WITH countries AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'countries') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
countries_rename AS (
|
||||
|
||||
SELECT
|
||||
countries.id AS country_id,
|
||||
countries.name,
|
||||
countries.short_code,
|
||||
countries.phone_code,
|
||||
countries.deleted_at AS deleted_datetime,
|
||||
countries.created_at AS created_datetime,
|
||||
countries.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM countries
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__countries AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
short_code,
|
||||
phone_code,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM countries_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__countries
|
||||
@@ -0,0 +1,43 @@
|
||||
-- IMPORTS
|
||||
WITH currencies AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'currencies') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
currencies_rename AS (
|
||||
|
||||
SELECT
|
||||
currencies.id AS currency_id,
|
||||
currencies.country_id,
|
||||
currencies.name,
|
||||
currencies.short_code,
|
||||
currencies.symbol,
|
||||
currencies.deleted_at AS deleted_datetime,
|
||||
currencies.created_at AS created_datetime,
|
||||
currencies.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM currencies
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__currencies AS (
|
||||
|
||||
SELECT
|
||||
currency_id,
|
||||
country_id,
|
||||
name,
|
||||
short_code,
|
||||
symbol,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM currencies_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__currencies
|
||||
@@ -0,0 +1,60 @@
|
||||
-- IMPORTS
|
||||
WITH currency_rate_logs AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'currency_rate_logs') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
currency_rate_logs_clean_list AS (
|
||||
|
||||
SELECT
|
||||
id,
|
||||
round(1/selling, 5) AS selling
|
||||
FROM
|
||||
currency_rate_logs
|
||||
WHERE
|
||||
id IN ('579','580','581','582')
|
||||
),
|
||||
|
||||
currency_rate_logs_rename_clean_wrong_rate AS (
|
||||
|
||||
SELECT
|
||||
currency_rate_logs.id AS currency_rate_log_id,
|
||||
currency_rate_logs.currency_rate_id,
|
||||
COALESCE(currency_rate_logs_clean_list.selling, currency_rate_logs.selling) AS base_to_quote_currency_exchange_rate,
|
||||
currency_rate_logs.created_by AS creator_user_id,
|
||||
currency_rate_logs.created_at AS created_datetime,
|
||||
currency_rate_logs.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM currency_rate_logs
|
||||
|
||||
LEFT JOIN currency_rate_logs_clean_list
|
||||
ON (currency_rate_logs.id = currency_rate_logs_clean_list.id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__currency_rate_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
currency_rate_log_id,
|
||||
currency_rate_id,
|
||||
creator_user_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
base_to_quote_currency_exchange_rate,
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM currency_rate_logs_rename_clean_wrong_rate
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__currency_rate_logs
|
||||
@@ -0,0 +1,51 @@
|
||||
-- IMPORTS
|
||||
WITH currency_rates AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'currency_rates') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
currency_rates_rename AS (
|
||||
|
||||
SELECT
|
||||
currency_rates.id AS currency_rate_id,
|
||||
currency_rates.currency_id AS quote_currency_id,
|
||||
currency_rates.selling AS base_to_quote_currency_exchange_rate,
|
||||
currency_rates.payment_method_type AS payment_method,
|
||||
currency_rates.service_id AS service_type,
|
||||
currency_rates.deleted_at AS deleted_datetime,
|
||||
currency_rates.created_at AS created_datetime,
|
||||
currency_rates.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM currency_rates
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__currency_rates AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
currency_rate_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
payment_method,
|
||||
service_type,
|
||||
|
||||
-- measures
|
||||
base_to_quote_currency_exchange_rate,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM currency_rates_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__currency_rates
|
||||
@@ -0,0 +1,53 @@
|
||||
-- IMPORTS
|
||||
WITH districts AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'districts') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
districts_rename AS (
|
||||
|
||||
SELECT
|
||||
districts.id AS district_id,
|
||||
districts.country_id,
|
||||
districts.state_id,
|
||||
districts.name,
|
||||
districts.postcode,
|
||||
districts.status,
|
||||
districts.deleted_at AS deleted_datetime,
|
||||
districts.created_at AS created_datetime,
|
||||
districts.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM districts
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__districts AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
district_id,
|
||||
country_id,
|
||||
state_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
postcode,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM districts_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__districts
|
||||
@@ -0,0 +1,62 @@
|
||||
-- IMPORTS
|
||||
WITH documents AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'documents') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
documents_rename AS (
|
||||
|
||||
SELECT
|
||||
documents.id AS document_id,
|
||||
documents.owner_type,
|
||||
documents.owner_id,
|
||||
documents.document_type,
|
||||
documents.reference,
|
||||
documents.status,
|
||||
documents.issued_date AS issued_datetime,
|
||||
documents.expired_date AS expired_datetime,
|
||||
documents.approver AS approver_user_id,
|
||||
documents.approval_date AS approved_datetime,
|
||||
documents.deleted_at AS deleted_datetime,
|
||||
documents.created_at AS created_datetime,
|
||||
documents.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM documents
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__documents AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
document_id,
|
||||
owner_id,
|
||||
|
||||
-- dimensions
|
||||
owner_type,
|
||||
document_type,
|
||||
reference,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
issued_datetime,
|
||||
expired_datetime,
|
||||
approver_user_id,
|
||||
approved_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM documents_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__documents
|
||||
@@ -0,0 +1,62 @@
|
||||
-- IMPORTS
|
||||
WITH groups AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'groups') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
groups_rename AS (
|
||||
|
||||
SELECT
|
||||
groups.id AS group_cost_id,
|
||||
groups.reference AS group_marking_id,
|
||||
groups.issuer AS supplier_user_id,
|
||||
groups.amount AS base_amount,
|
||||
groups.original_amount AS quote_amount,
|
||||
groups.currency_id AS base_currency_id,
|
||||
groups.original_currency_id AS quote_currency_id,
|
||||
groups.currency_rate AS base_to_quote_currency_exchange_rate,
|
||||
groups.tax AS base_tax,
|
||||
groups.service_charge AS base_service_charge,
|
||||
groups.status,
|
||||
groups.created_at AS created_datetime,
|
||||
groups.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM groups
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__group_costs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
group_cost_id,
|
||||
group_marking_id,
|
||||
supplier_user_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
|
||||
-- measures
|
||||
base_amount,
|
||||
quote_amount,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM groups_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__group_costs
|
||||
@@ -0,0 +1,46 @@
|
||||
-- IMPORTS
|
||||
WITH segments AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'segments') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
segments_rename AS (
|
||||
|
||||
SELECT
|
||||
segments.id AS segment_id,
|
||||
UPPER(segments.name) AS name,
|
||||
segments.type AS segment_type,
|
||||
segments.deleted_at AS deleted_datetime,
|
||||
segments.created_at AS created_datetime,
|
||||
segments.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM segments
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__segments AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
segment_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
segment_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM segments_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__segments
|
||||
@@ -0,0 +1,48 @@
|
||||
-- IMPORTS
|
||||
WITH service_types AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'service_types') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
service_types_rename AS (
|
||||
|
||||
SELECT
|
||||
service_types.id AS service_type_id,
|
||||
service_types.name,
|
||||
service_types.status,
|
||||
service_types.deleted_at AS deleted_datetime,
|
||||
service_types.created_at AS created_datetime,
|
||||
service_types.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM service_types
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__service_types AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
service_type_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM service_types_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__service_types
|
||||
@@ -0,0 +1,50 @@
|
||||
-- IMPORTS
|
||||
WITH states AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'states') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
states_rename AS (
|
||||
|
||||
SELECT
|
||||
states.id AS state_id,
|
||||
states.country_id,
|
||||
states.name,
|
||||
states.status,
|
||||
states.deleted_at AS deleted_datetime,
|
||||
states.created_at AS created_datetime,
|
||||
states.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM states
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__states AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
state_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM states_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__states
|
||||
@@ -0,0 +1,81 @@
|
||||
-- IMPORTS
|
||||
WITH transaction_logs AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'transaction_logs') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transaction_logs_rename AS (
|
||||
|
||||
SELECT
|
||||
transaction_logs.id AS transaction_log_id,
|
||||
transaction_logs.transaction_id,
|
||||
transaction_logs.owner_type,
|
||||
transaction_logs.owner_id,
|
||||
transaction_logs.type AS transaction_type,
|
||||
transaction_logs.issuer AS issuer_user_id,
|
||||
transaction_logs.receiver AS receiver_user_id,
|
||||
transaction_logs.recipient_bank_account_id AS recipient_bank_id,
|
||||
transaction_logs.payment_method,
|
||||
transaction_logs.payment_reference,
|
||||
transaction_logs.bill_no AS bill_number,
|
||||
transaction_logs.amount AS base_value,
|
||||
transaction_logs.original_amount AS quote_value,
|
||||
transaction_logs.currency_id AS base_currency_id,
|
||||
transaction_logs.original_currency_id AS quote_currency_id,
|
||||
transaction_logs.currency_rate AS base_to_quote_currency_exchange_rate,
|
||||
transaction_logs.tax AS base_tax,
|
||||
transaction_logs.service_charge AS base_service_charge,
|
||||
transaction_logs.expires_on AS expired_datetime,
|
||||
transaction_logs.status,
|
||||
transaction_logs.deleted_at AS deleted_datetime,
|
||||
transaction_logs.created_at AS created_datetime,
|
||||
transaction_logs.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transaction_logs
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__transaction_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_log_id,
|
||||
transaction_id,
|
||||
owner_id,
|
||||
issuer_user_id,
|
||||
receiver_user_id,
|
||||
recipient_bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimentions
|
||||
owner_type,
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transaction_logs_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__transaction_logs
|
||||
@@ -0,0 +1,79 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'transactions') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transactions_rename AS (
|
||||
|
||||
SELECT
|
||||
transactions.id AS transaction_id,
|
||||
transactions.owner_type,
|
||||
transactions.owner_id,
|
||||
transactions.type AS transaction_type,
|
||||
transactions.issuer AS issuer_user_id,
|
||||
transactions.receiver AS receiver_user_id,
|
||||
transactions.recipient_bank_account_id AS recipient_bank_id,
|
||||
transactions.payment_method,
|
||||
transactions.payment_reference,
|
||||
transactions.bill_no AS bill_number,
|
||||
transactions.amount AS base_value,
|
||||
transactions.original_amount AS quote_value,
|
||||
transactions.currency_id AS base_currency_id,
|
||||
transactions.original_currency_id AS quote_currency_id,
|
||||
transactions.currency_rate AS base_to_quote_currency_exchange_rate,
|
||||
transactions.tax AS base_tax,
|
||||
transactions.service_charge AS base_service_charge,
|
||||
transactions.expires_on AS expired_datetime,
|
||||
transactions.status,
|
||||
transactions.deleted_at AS deleted_datetime,
|
||||
transactions.created_at AS created_datetime,
|
||||
transactions.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transactions
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__transactions AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_id,
|
||||
owner_id,
|
||||
issuer_user_id,
|
||||
receiver_user_id,
|
||||
recipient_bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimentions
|
||||
owner_type,
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transactions_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__transactions
|
||||
@@ -0,0 +1,47 @@
|
||||
-- IMPORTS
|
||||
WITH user_email_verifications AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'user_email_verifications') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
user_email_verifications_rename AS (
|
||||
|
||||
SELECT
|
||||
user_email_verifications.id AS user_email_verification_id,
|
||||
user_email_verifications.email,
|
||||
user_email_verifications.is_complete AS is_completed,
|
||||
user_email_verifications.is_sent,
|
||||
user_email_verifications.created_at AS created_datetime,
|
||||
user_email_verifications.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM user_email_verifications
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__user_email_verifications AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
user_email_verification_id,
|
||||
|
||||
-- dimensions
|
||||
email,
|
||||
is_completed,
|
||||
is_sent,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM user_email_verifications_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__user_email_verifications
|
||||
@@ -0,0 +1,51 @@
|
||||
-- IMPORTS
|
||||
WITH users AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'users') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
users_rename_and_clean_null_data AS (
|
||||
|
||||
SELECT
|
||||
users.id AS user_id,
|
||||
users.name,
|
||||
users.email,
|
||||
users.type AS user_type,
|
||||
users.status,
|
||||
users.deleted_at AS deleted_datetime,
|
||||
|
||||
-- User without create_datetime because it migrate from old system, we get minimum user create datetime to replace it
|
||||
COALESCE(users.created_at, CAST('2021-05-13 00:00:00 +08:00' AS DATETIME)) AS created_datetime,
|
||||
users.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM users
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__users AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
email,
|
||||
user_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM users_rename_and_clean_null_data
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__users
|
||||
@@ -0,0 +1,54 @@
|
||||
-- IMPORTS
|
||||
WITH activity_logs AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'activity_log') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
activity_logs_rename AS (
|
||||
|
||||
SELECT
|
||||
activity_logs.id AS activity_log_id,
|
||||
activity_logs.log_name,
|
||||
activity_logs.description,
|
||||
activity_logs.subject_id,
|
||||
activity_logs.subject_type,
|
||||
activity_logs.causer_id,
|
||||
activity_logs.causer_type,
|
||||
activity_logs.properties,
|
||||
activity_logs.created_at AS created_datetime,
|
||||
activity_logs.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM activity_logs
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__activity_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
activity_log_id,
|
||||
subject_id,
|
||||
causer_id,
|
||||
|
||||
-- dimensions
|
||||
log_name,
|
||||
description,
|
||||
subject_type,
|
||||
causer_type,
|
||||
properties,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM activity_logs_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__activity_logs
|
||||
@@ -0,0 +1,81 @@
|
||||
-- IMPORTS
|
||||
WITH banks AS (
|
||||
SELECT * FROM {{ ref('base_exchange__banks') }}
|
||||
),
|
||||
|
||||
bank_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__bank_types') }}
|
||||
WHERE category = 'REPHRASE'
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
banks_change_column_value AS (
|
||||
|
||||
SELECT
|
||||
banks.bank_id,
|
||||
banks.company_id,
|
||||
banks.recipient_reference,
|
||||
banks.bank_name,
|
||||
banks.holder_name,
|
||||
banks.account_number,
|
||||
banks.bank_branch,
|
||||
banks.swift_code,
|
||||
banks.cnaps_code,
|
||||
COALESCE(bank_types.name, banks.bank_type::string) AS bank_type,
|
||||
banks.is_default,
|
||||
COALESCE(status.name, banks.status::string) AS status,
|
||||
banks.country_id,
|
||||
banks.deleted_datetime,
|
||||
banks.created_datetime,
|
||||
banks.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM banks
|
||||
|
||||
LEFT JOIN bank_types
|
||||
ON (banks.bank_type = bank_types.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (banks.status = status.id)
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__banks AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
bank_id,
|
||||
company_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
bank_type,
|
||||
is_default,
|
||||
account_number,
|
||||
bank_name,
|
||||
bank_branch,
|
||||
holder_name,
|
||||
swift_code,
|
||||
cnaps_code,
|
||||
recipient_reference,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM banks_change_column_value
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__banks
|
||||
@@ -0,0 +1,50 @@
|
||||
-- IMPORTS
|
||||
WITH documents AS (
|
||||
SELECT * FROM {{ ref('base_exchange__documents') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
documents_join_status AS (
|
||||
|
||||
SELECT
|
||||
documents.document_id,
|
||||
IFF(documents.owner_type = 'App\\Models\\Booking', documents.owner_id, null) AS booking_id,
|
||||
documents.document_type,
|
||||
documents.deleted_datetime,
|
||||
documents.created_datetime,
|
||||
documents.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM documents
|
||||
|
||||
WHERE
|
||||
owner_type = 'App\\Models\\Booking'
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__booking_documents AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
document_id,
|
||||
booking_id,
|
||||
|
||||
-- dimensions
|
||||
document_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM documents_join_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__booking_documents
|
||||
@@ -0,0 +1,124 @@
|
||||
-- IMPORTS
|
||||
WITH booking_arch_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__booking_arch_logs') }}
|
||||
),
|
||||
|
||||
bookings AS (
|
||||
SELECT * FROM {{ ref('base_exchange__bookings') }}
|
||||
),
|
||||
|
||||
activity_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__activity_logs') }}
|
||||
),
|
||||
|
||||
service_types AS (
|
||||
SELECT * FROM {{ ref('base_exchange__service_types') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
booking_id_brg_user_id AS (
|
||||
|
||||
SELECT
|
||||
subject_id AS booking_id,
|
||||
causer_id AS user_id
|
||||
FROM
|
||||
activity_logs
|
||||
WHERE
|
||||
subject_type='App\\Models\\Booking'
|
||||
AND
|
||||
description='created'
|
||||
),
|
||||
|
||||
bookings_generate_booking_log_id AS (
|
||||
SELECT
|
||||
MD5_NUMBER_LOWER64(CONCAT(booking_id, created_datetime)) AS booking_log_id,
|
||||
*
|
||||
|
||||
FROM bookings
|
||||
),
|
||||
|
||||
booking_arch_logs_union_bookings AS (
|
||||
SELECT * FROM bookings_generate_booking_log_id
|
||||
UNION
|
||||
SELECT * FROM booking_arch_logs
|
||||
),
|
||||
|
||||
|
||||
booking_logs_map_column_and_value_transform AS (
|
||||
|
||||
SELECT
|
||||
booking_arch_logs_union_bookings.booking_log_id,
|
||||
booking_arch_logs_union_bookings.booking_id,
|
||||
booking_arch_logs_union_bookings.booking_marking_id,
|
||||
booking_arch_logs_union_bookings.company_id,
|
||||
booking_arch_logs_union_bookings.bank_id,
|
||||
|
||||
booking_id_brg_user_id.user_id,
|
||||
|
||||
COALESCE(service_types.name, booking_arch_logs_union_bookings.service_type::string) AS service_type,
|
||||
|
||||
booking_arch_logs_union_bookings.fix_value,
|
||||
|
||||
booking_arch_logs_union_bookings.fix_currency_id,
|
||||
booking_arch_logs_union_bookings.quote_currency_id,
|
||||
booking_arch_logs_union_bookings.base_currency_id,
|
||||
COALESCE(status.name, booking_arch_logs_union_bookings.status::string) AS status,
|
||||
|
||||
booking_arch_logs_union_bookings.deleted_datetime,
|
||||
booking_arch_logs_union_bookings.created_datetime,
|
||||
booking_arch_logs_union_bookings.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM booking_arch_logs_union_bookings
|
||||
|
||||
LEFT JOIN booking_id_brg_user_id
|
||||
ON (booking_arch_logs_union_bookings.booking_id = booking_id_brg_user_id.booking_id)
|
||||
|
||||
LEFT JOIN service_types
|
||||
ON (booking_arch_logs_union_bookings.service_type = service_types.service_type_id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (booking_arch_logs_union_bookings.status = status.id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__booking_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
booking_log_id,
|
||||
booking_id,
|
||||
booking_marking_id,
|
||||
company_id,
|
||||
user_id,
|
||||
bank_id,
|
||||
fix_currency_id,
|
||||
quote_currency_id,
|
||||
base_currency_id,
|
||||
|
||||
-- dimensions
|
||||
service_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
fix_value,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM booking_logs_map_column_and_value_transform
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__booking_logs
|
||||
@@ -0,0 +1,104 @@
|
||||
-- IMPORTS
|
||||
WITH bookings AS (
|
||||
SELECT * FROM {{ ref('base_exchange__bookings') }}
|
||||
),
|
||||
|
||||
activity_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__activity_logs') }}
|
||||
),
|
||||
|
||||
service_types AS (
|
||||
SELECT * FROM {{ ref('base_exchange__service_types') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
booking_id_brg_user_id AS (
|
||||
|
||||
SELECT
|
||||
subject_id AS booking_id,
|
||||
causer_id AS user_id
|
||||
FROM
|
||||
activity_logs
|
||||
WHERE
|
||||
subject_type='App\\Models\\Booking'
|
||||
AND
|
||||
description='created'
|
||||
),
|
||||
|
||||
|
||||
bookings_map_column_and_value_transform AS (
|
||||
|
||||
SELECT
|
||||
bookings.booking_id,
|
||||
bookings.booking_marking_id,
|
||||
bookings.company_id,
|
||||
bookings.bank_id,
|
||||
|
||||
booking_id_brg_user_id.user_id,
|
||||
|
||||
COALESCE(service_types.name, bookings.service_type::string) AS service_type,
|
||||
|
||||
bookings.fix_value,
|
||||
|
||||
bookings.fix_currency_id,
|
||||
bookings.quote_currency_id,
|
||||
bookings.base_currency_id,
|
||||
COALESCE(status.name, bookings.status::string) AS status,
|
||||
|
||||
bookings.deleted_datetime,
|
||||
bookings.created_datetime,
|
||||
bookings.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM bookings
|
||||
|
||||
LEFT JOIN booking_id_brg_user_id
|
||||
ON (bookings.booking_id = booking_id_brg_user_id.booking_id)
|
||||
|
||||
LEFT JOIN service_types
|
||||
ON (bookings.service_type = service_types.service_type_id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (bookings.status = status.id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__booking_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
booking_id,
|
||||
booking_marking_id,
|
||||
company_id,
|
||||
user_id,
|
||||
bank_id,
|
||||
fix_currency_id,
|
||||
quote_currency_id,
|
||||
base_currency_id,
|
||||
|
||||
-- dimensions
|
||||
service_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
fix_value,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM bookings_map_column_and_value_transform
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__booking_logs
|
||||
@@ -0,0 +1,81 @@
|
||||
-- IMPORTS
|
||||
WITH companies AS (
|
||||
SELECT * FROM {{ ref('base_exchange__companies') }}
|
||||
),
|
||||
|
||||
company_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__company_types') }}
|
||||
WHERE category = '2_AS_CORPORATE'
|
||||
),
|
||||
|
||||
business_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__business_types') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
companies_map_constant AS (
|
||||
|
||||
SELECT
|
||||
companies.company_id,
|
||||
companies.name,
|
||||
companies.company_marking_id,
|
||||
companies.autocount_id,
|
||||
|
||||
COALESCE(company_types.name, companies.company_type::string) AS company_type,
|
||||
COALESCE(business_types.name, companies.business_type::string) AS business_type,
|
||||
COALESCE(status.name, companies.status::string) AS status,
|
||||
|
||||
companies.deleted_datetime,
|
||||
companies.created_datetime,
|
||||
companies.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM companies
|
||||
|
||||
LEFT JOIN company_types
|
||||
ON (companies.company_type = company_types.id)
|
||||
|
||||
LEFT JOIN business_types
|
||||
ON (companies.business_type = business_types.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (companies.status = status.id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_companies__exchange AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
company_id,
|
||||
company_marking_id,
|
||||
autocount_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
company_type,
|
||||
business_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM companies_map_constant
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_companies__exchange
|
||||
@@ -0,0 +1,43 @@
|
||||
-- IMPORTS
|
||||
WITH snap_segment_companies AS (
|
||||
SELECT * FROM {{ ref('snap_exchange__segment_companies') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
segment_companies_rename AS (
|
||||
|
||||
SELECT
|
||||
snap_segment_companies.segment_id,
|
||||
snap_segment_companies.company_id,
|
||||
snap_segment_companies.dbt_valid_from AS dbt_valid_from_datetime,
|
||||
snap_segment_companies.dbt_valid_to AS dbt_valid_to_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM snap_segment_companies
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__companies_brg_segments AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
segment_id,
|
||||
company_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
dbt_valid_from_datetime,
|
||||
dbt_valid_to_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM segment_companies_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__companies_brg_segments
|
||||
@@ -0,0 +1,39 @@
|
||||
-- IMPORTS
|
||||
WITH employees AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'employees') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
employees_column_rename_and_drop_unuse_column AS (
|
||||
|
||||
SELECT
|
||||
employees.company_id,
|
||||
employees.user_id,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM employees
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__companies_brg_users AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
company_id,
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM employees_column_rename_and_drop_unuse_column
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__companies_brg_users
|
||||
@@ -0,0 +1,92 @@
|
||||
-- IMPORTS
|
||||
WITH company_addresses AS (
|
||||
SELECT * FROM {{ ref('base_exchange__company_addresses') }}
|
||||
),
|
||||
|
||||
countries AS (
|
||||
SELECT * FROM {{ ref('base_exchange__countries') }}
|
||||
),
|
||||
|
||||
states AS (
|
||||
SELECT * FROM {{ ref('base_exchange__states') }}
|
||||
),
|
||||
|
||||
districts AS (
|
||||
SELECT * FROM {{ ref('base_exchange__districts') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
company_addressess_join_companies_countries_states_districts AS (
|
||||
|
||||
SELECT
|
||||
company_addresses.company_address_id,
|
||||
company_addresses.company_id,
|
||||
|
||||
company_addresses.country_id,
|
||||
countries.name AS country_name,
|
||||
countries.short_code AS country_short_code,
|
||||
countries.phone_code AS country_phone_code,
|
||||
|
||||
company_addresses.state_id,
|
||||
states.name AS state_name,
|
||||
|
||||
company_addresses.district_id,
|
||||
districts.name AS district_name,
|
||||
|
||||
company_addresses.postcode,
|
||||
company_addresses.address_line_one,
|
||||
company_addresses.address_line_two,
|
||||
company_addresses.is_billing_address,
|
||||
company_addresses.deleted_datetime,
|
||||
company_addresses.created_datetime,
|
||||
company_addresses.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM company_addresses
|
||||
|
||||
LEFT JOIN countries
|
||||
ON (company_addresses.country_id = countries.country_id)
|
||||
|
||||
LEFT JOIN states
|
||||
ON (company_addresses.state_id = states.state_id)
|
||||
|
||||
LEFT JOIN districts
|
||||
ON (company_addresses.district_id = districts.district_id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__company_addresses AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
company_address_id,
|
||||
company_id,
|
||||
country_id,
|
||||
state_id,
|
||||
district_id,
|
||||
|
||||
-- dimensions
|
||||
country_name,
|
||||
country_short_code,
|
||||
country_phone_code,
|
||||
state_name,
|
||||
district_name,
|
||||
postcode,
|
||||
address_line_one,
|
||||
address_line_two,
|
||||
is_billing_address,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM company_addressess_join_companies_countries_states_districts
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__company_addresses
|
||||
@@ -0,0 +1,67 @@
|
||||
-- IMPORTS
|
||||
WITH contacts AS (
|
||||
SELECT * FROM {{ ref('base_exchange__company_contacts') }}
|
||||
),
|
||||
|
||||
countries AS (
|
||||
SELECT * FROM {{ ref('base_exchange__countries') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
companies_join_countries AS (
|
||||
|
||||
SELECT
|
||||
contacts.contact_id,
|
||||
contacts.company_id,
|
||||
|
||||
contacts.country_id,
|
||||
countries.name AS country_name,
|
||||
|
||||
contacts.contact_name,
|
||||
contacts.phone,
|
||||
contacts.email,
|
||||
contacts.wechat,
|
||||
contacts.deleted_datetime,
|
||||
contacts.created_datetime,
|
||||
contacts.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM contacts
|
||||
|
||||
LEFT JOIN countries
|
||||
ON (contacts.country_id = countries.country_id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__company_contacts AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
contact_id,
|
||||
company_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
country_name,
|
||||
contact_name,
|
||||
phone,
|
||||
email,
|
||||
wechat,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM companies_join_countries
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__company_contacts
|
||||
@@ -0,0 +1,66 @@
|
||||
-- IMPORTS
|
||||
WITH documents AS (
|
||||
SELECT * FROM {{ ref('base_exchange__documents') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
documents_join_status AS (
|
||||
|
||||
SELECT
|
||||
documents.document_id,
|
||||
IFF(documents.owner_type = 'App\\Models\\Company', documents.owner_id, null) AS company_id,
|
||||
documents.document_type,
|
||||
documents.reference,
|
||||
COALESCE(status.name, documents.status::string) AS status,
|
||||
documents.approver_user_id,
|
||||
documents.approved_datetime,
|
||||
documents.deleted_datetime,
|
||||
documents.created_datetime,
|
||||
documents.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM documents
|
||||
|
||||
LEFT JOIN status
|
||||
ON (documents.status = status.id)
|
||||
|
||||
WHERE
|
||||
owner_type = 'App\\Models\\Company'
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__company_documents AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
document_id,
|
||||
company_id,
|
||||
approver_user_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
document_type,
|
||||
reference,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
approved_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM documents_join_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__company_documents
|
||||
@@ -0,0 +1,51 @@
|
||||
-- IMPORTS
|
||||
WITH wallets AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'wallets') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
wallets_rename AS (
|
||||
|
||||
SELECT
|
||||
wallets.id AS wallet_id,
|
||||
IFF(wallets.owner_type = 'App//Models//Company', wallets.owner_id, null) AS company_id,
|
||||
wallets.code AS wallet_code,
|
||||
wallets.currency_id,
|
||||
wallets.amount,
|
||||
wallets.deleted_at AS deleted_datetime,
|
||||
wallets.created_at AS created_datetime,
|
||||
wallets.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM wallets
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__company_wallets AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
wallet_id,
|
||||
wallet_code,
|
||||
company_id,
|
||||
currency_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
amount,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM wallets_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__company_wallets
|
||||
@@ -0,0 +1,64 @@
|
||||
-- IMPORTS
|
||||
WITH currencies AS (
|
||||
SELECT * FROM {{ ref('base_exchange__currencies') }}
|
||||
),
|
||||
|
||||
countries AS (
|
||||
SELECT * FROM {{ ref('base_exchange__countries') }}
|
||||
),
|
||||
|
||||
|
||||
|
||||
-- LOGIC
|
||||
currencies_join_countries AS (
|
||||
|
||||
SELECT
|
||||
currencies.currency_id,
|
||||
|
||||
currencies.country_id,
|
||||
countries.name AS country_name,
|
||||
|
||||
currencies.name,
|
||||
currencies.short_code,
|
||||
currencies.symbol,
|
||||
currencies.deleted_datetime,
|
||||
currencies.created_datetime,
|
||||
currencies.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM currencies
|
||||
|
||||
LEFT JOIN countries
|
||||
ON (currencies.country_id = countries.country_id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__currencies AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
currency_id,
|
||||
country_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
short_code,
|
||||
symbol,
|
||||
country_name,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM currencies_join_countries
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__currencies
|
||||
@@ -0,0 +1,172 @@
|
||||
-- IMPORTS
|
||||
WITH currency_rate_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__currency_rate_logs') }}
|
||||
),
|
||||
|
||||
currencies AS (
|
||||
SELECT * FROM {{ ref('base_exchange__currencies') }}
|
||||
),
|
||||
|
||||
currency_rates AS (
|
||||
SELECT * FROM {{ ref('base_exchange__currency_rates') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
service_types AS (
|
||||
SELECT * FROM {{ ref('base_exchange__service_types') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
currency_rate_logs_join_currency_rates AS (
|
||||
|
||||
SELECT
|
||||
currency_rate_logs.currency_rate_log_id,
|
||||
currency_rate_logs.currency_rate_id,
|
||||
|
||||
currency_rates.quote_currency_id,
|
||||
currency_rate_logs.base_to_quote_currency_exchange_rate,
|
||||
currency_rates.payment_method,
|
||||
currency_rates.service_type,
|
||||
|
||||
currency_rate_logs.creator_user_id,
|
||||
currency_rate_logs.created_datetime,
|
||||
currency_rate_logs.updated_datetime
|
||||
|
||||
FROM currency_rate_logs
|
||||
|
||||
LEFT JOIN currency_rates
|
||||
ON (currency_rate_logs.currency_rate_id = currency_rates.currency_rate_id)
|
||||
),
|
||||
|
||||
|
||||
currency_rate_logs_quote_currency_id_join_currencies AS (
|
||||
|
||||
SELECT
|
||||
currency_rate_logs_join_currency_rates.currency_rate_log_id,
|
||||
currency_rate_logs_join_currency_rates.currency_rate_id,
|
||||
|
||||
currency_rate_logs_join_currency_rates.quote_currency_id,
|
||||
currencies.name AS quote_currency_name,
|
||||
currencies.short_code AS quote_currency_short_code,
|
||||
currencies.symbol AS quote_currency_symbol,
|
||||
|
||||
currency_rate_logs_join_currency_rates.base_to_quote_currency_exchange_rate,
|
||||
|
||||
COALESCE(payment_methods.name, currency_rate_logs_join_currency_rates.payment_method::string) AS payment_method,
|
||||
COALESCE(service_types.name, currency_rate_logs_join_currency_rates.service_type::string) AS service_type,
|
||||
|
||||
currency_rate_logs_join_currency_rates.creator_user_id,
|
||||
currency_rate_logs_join_currency_rates.created_datetime,
|
||||
currency_rate_logs_join_currency_rates.updated_datetime
|
||||
|
||||
FROM
|
||||
currency_rate_logs_join_currency_rates
|
||||
|
||||
LEFT JOIN currencies
|
||||
ON (currency_rate_logs_join_currency_rates.quote_currency_id = currencies.currency_id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (currency_rate_logs_join_currency_rates.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN service_types
|
||||
ON (currency_rate_logs_join_currency_rates.service_type = service_types.service_type_id)
|
||||
),
|
||||
|
||||
currency_rate_logs_add_dense_rank AS (
|
||||
|
||||
SELECT
|
||||
currency_rate_logs_quote_currency_id_join_currencies.currency_rate_log_id,
|
||||
|
||||
dense_rank() OVER
|
||||
(PARTITION BY currency_rate_logs_quote_currency_id_join_currencies.currency_rate_id
|
||||
ORDER BY currency_rate_logs_quote_currency_id_join_currencies.created_datetime) AS dense_rank_index,
|
||||
|
||||
currency_rate_logs_quote_currency_id_join_currencies.currency_rate_id AS currency_rate_id,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.quote_currency_id,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.quote_currency_name,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.quote_currency_short_code,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.quote_currency_symbol,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.payment_method,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.service_type,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.base_to_quote_currency_exchange_rate,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.creator_user_id,
|
||||
currency_rate_logs_quote_currency_id_join_currencies.created_datetime
|
||||
|
||||
FROM currency_rate_logs_quote_currency_id_join_currencies
|
||||
|
||||
ORDER BY
|
||||
currency_rate_id,
|
||||
created_datetime
|
||||
),
|
||||
|
||||
|
||||
currency_rate_logs_resturucure AS (
|
||||
SELECT
|
||||
currency_rate_logs_add_dense_rank.currency_rate_log_id,
|
||||
currency_rate_logs_add_dense_rank.currency_rate_id,
|
||||
currency_rate_logs_add_dense_rank.quote_currency_id,
|
||||
currency_rate_logs_add_dense_rank.quote_currency_name,
|
||||
currency_rate_logs_add_dense_rank.quote_currency_short_code,
|
||||
currency_rate_logs_add_dense_rank.quote_currency_symbol,
|
||||
currency_rate_logs_add_dense_rank.payment_method,
|
||||
currency_rate_logs_add_dense_rank.service_type,
|
||||
currency_rate_logs_add_dense_rank.base_to_quote_currency_exchange_rate,
|
||||
currency_rate_logs_add_dense_rank.creator_user_id,
|
||||
|
||||
CASE
|
||||
WHEN currency_rate_logs_add_dense_rank.dense_rank_index=1 THEN CAST('1990-01-01 00:00:00 +08:00' AS DATETIME)
|
||||
ELSE currency_rate_logs_add_dense_rank.created_datetime
|
||||
END AS from_datetime,
|
||||
|
||||
COALESCE(currency_rate_logs_add_dense_rank_clone.created_datetime,
|
||||
CAST('2999-12-31 23:59:59 +08:00' AS DATETIME)) AS to_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM
|
||||
currency_rate_logs_add_dense_rank
|
||||
|
||||
LEFT JOIN currency_rate_logs_add_dense_rank AS currency_rate_logs_add_dense_rank_clone
|
||||
ON currency_rate_logs_add_dense_rank.dense_rank_index = currency_rate_logs_add_dense_rank_clone.dense_rank_index-1
|
||||
AND currency_rate_logs_add_dense_rank.currency_rate_id = currency_rate_logs_add_dense_rank_clone.currency_rate_id
|
||||
|
||||
ORDER BY currency_rate_logs_add_dense_rank.currency_rate_id, currency_rate_logs_add_dense_rank.created_datetime
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__currency_rate_logs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
currency_rate_log_id,
|
||||
currency_rate_id,
|
||||
quote_currency_id,
|
||||
creator_user_id,
|
||||
|
||||
-- dimensions
|
||||
quote_currency_name,
|
||||
quote_currency_short_code,
|
||||
quote_currency_symbol,
|
||||
payment_method,
|
||||
service_type,
|
||||
|
||||
-- measures
|
||||
base_to_quote_currency_exchange_rate,
|
||||
|
||||
-- date/times
|
||||
from_datetime,
|
||||
to_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM currency_rate_logs_resturucure
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__currency_rate_logs
|
||||
@@ -0,0 +1,49 @@
|
||||
-- IMPORTS
|
||||
WITH documents AS (
|
||||
SELECT * FROM {{ ref('base_exchange__documents') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
documents_join_status AS (
|
||||
|
||||
SELECT
|
||||
documents.document_id,
|
||||
IFF(documents.owner_type = 'App\\Models\\Group', documents.owner_id, null) AS group_cost_id,
|
||||
documents.document_type,
|
||||
documents.deleted_datetime,
|
||||
documents.created_datetime,
|
||||
documents.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM documents
|
||||
|
||||
WHERE
|
||||
owner_type = 'App\\Models\\Group'
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__group_cost_documents AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
document_id,
|
||||
group_cost_id,
|
||||
|
||||
-- dimensions
|
||||
document_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM documents_join_status
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__group_cost_documents
|
||||
@@ -0,0 +1,76 @@
|
||||
-- IMPORTS
|
||||
WITH group_costs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__group_costs') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
group_costs_join_currencies_status AS (
|
||||
|
||||
SELECT
|
||||
group_costs.group_cost_id,
|
||||
|
||||
group_costs.group_marking_id,
|
||||
group_costs.supplier_user_id,
|
||||
group_costs.base_amount,
|
||||
group_costs.quote_amount,
|
||||
|
||||
group_costs.base_currency_id,
|
||||
|
||||
group_costs.quote_currency_id,
|
||||
|
||||
group_costs.base_to_quote_currency_exchange_rate,
|
||||
group_costs.base_tax,
|
||||
group_costs.base_service_charge,
|
||||
|
||||
COALESCE(status.name, group_costs.status::string) AS status,
|
||||
|
||||
group_costs.created_datetime,
|
||||
group_costs.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM group_costs
|
||||
|
||||
LEFT JOIN status
|
||||
ON (group_costs.status = status.id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__group_costs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
group_cost_id,
|
||||
group_marking_id,
|
||||
supplier_user_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
|
||||
-- measures
|
||||
base_amount,
|
||||
quote_amount,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM group_costs_join_currencies_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__group_costs
|
||||
@@ -0,0 +1,55 @@
|
||||
-- IMPORTS
|
||||
WITH segments AS (
|
||||
SELECT * FROM {{ ref('base_exchange__segments') }}
|
||||
),
|
||||
|
||||
segment_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__segment_types') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
segments_join_segment_types AS (
|
||||
|
||||
SELECT
|
||||
segments.segment_id,
|
||||
segments.name,
|
||||
COALESCE(segment_types.name, segments.segment_type::string) AS segment_type,
|
||||
segments.deleted_datetime,
|
||||
segments.created_datetime,
|
||||
segments.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM segments
|
||||
|
||||
LEFT JOIN segment_types
|
||||
ON (segments.segment_type = segment_types.id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__segments AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
segment_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
segment_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM segments_join_segment_types
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__segments
|
||||
@@ -0,0 +1,140 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_arch_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transaction_arch_logs') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
transactions_generate_transaction_log_id AS (
|
||||
SELECT
|
||||
MD5_NUMBER_LOWER64(CONCAT(transactions.transaction_id, transactions.created_datetime)) AS transaction_log_id,
|
||||
*
|
||||
|
||||
FROM transactions
|
||||
),
|
||||
|
||||
|
||||
transaction_arch_logs_union_transactions AS (
|
||||
SELECT * FROM transactions_generate_transaction_log_id
|
||||
UNION
|
||||
SELECT * FROM transaction_arch_logs
|
||||
),
|
||||
|
||||
|
||||
union_transaction_rename_column_and_column_value AS (
|
||||
|
||||
SELECT
|
||||
transaction_arch_logs_union_transactions.transaction_log_id AS transaction_cost_log_id,
|
||||
transaction_arch_logs_union_transactions.transaction_id AS transaction_cost_id,
|
||||
|
||||
IFF(transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Transaction',
|
||||
transaction_arch_logs_union_transactions.owner_id,
|
||||
null) AS transaction_order_id,
|
||||
|
||||
COALESCE(transaction_types.name, transaction_arch_logs_union_transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transaction_arch_logs_union_transactions.issuer_user_id AS supplier_company_id,
|
||||
transaction_arch_logs_union_transactions.receiver_user_id AS company_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.recipient_bank_id,
|
||||
|
||||
COALESCE(payment_methods.name, transaction_arch_logs_union_transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transaction_arch_logs_union_transactions.payment_reference,
|
||||
transaction_arch_logs_union_transactions.bill_number,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_value,
|
||||
transaction_arch_logs_union_transactions.quote_value,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.quote_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_to_quote_currency_exchange_rate,
|
||||
transaction_arch_logs_union_transactions.base_tax,
|
||||
transaction_arch_logs_union_transactions.base_service_charge,
|
||||
transaction_arch_logs_union_transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transaction_arch_logs_union_transactions.status::string) AS status,
|
||||
|
||||
transaction_arch_logs_union_transactions.deleted_datetime,
|
||||
transaction_arch_logs_union_transactions.created_datetime,
|
||||
transaction_arch_logs_union_transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transaction_arch_logs_union_transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transaction_arch_logs_union_transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transaction_arch_logs_union_transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transaction_arch_logs_union_transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Transaction'
|
||||
AND
|
||||
transaction_arch_logs_union_transactions.transaction_type = '3' --BILL
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_log_costs AS (
|
||||
|
||||
SELECT
|
||||
--ids
|
||||
transaction_cost_log_id,
|
||||
transaction_cost_id,
|
||||
transaction_order_id,
|
||||
supplier_company_id,
|
||||
company_id,
|
||||
recipient_bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimentions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM union_transaction_rename_column_and_column_value
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_log_costs
|
||||
@@ -0,0 +1,136 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transactions_join_transaction_types_payment_methods_currencies_status AS (
|
||||
|
||||
SELECT
|
||||
transactions.transaction_id AS transaction_cost_id,
|
||||
IFF(transactions.owner_type = 'App\\Models\\Transaction', transactions.owner_id, null) AS transaction_order_id,
|
||||
|
||||
COALESCE(transaction_types.name, transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transactions.issuer_user_id AS supplier_company_id,
|
||||
|
||||
transactions.recipient_bank_id AS bank_id,
|
||||
|
||||
COALESCE(payment_methods.name, transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transactions.payment_reference,
|
||||
transactions.bill_number,
|
||||
|
||||
transactions.base_value,
|
||||
transactions.quote_value,
|
||||
|
||||
transactions.base_currency_id,
|
||||
transactions.quote_currency_id,
|
||||
|
||||
transactions.base_to_quote_currency_exchange_rate,
|
||||
transactions.base_tax,
|
||||
transactions.base_service_charge,
|
||||
|
||||
transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transactions.status::string) AS status,
|
||||
|
||||
transactions.deleted_datetime,
|
||||
transactions.created_datetime,
|
||||
transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transactions.owner_type = 'App\\Models\\Transaction'
|
||||
AND
|
||||
transactions.transaction_type = '3' --BILL
|
||||
|
||||
),
|
||||
|
||||
remove_deleted_row AS (
|
||||
SELECT
|
||||
*
|
||||
|
||||
FROM transactions_join_transaction_types_payment_methods_currencies_status
|
||||
|
||||
WHERE deleted_datetime IS NULL
|
||||
),
|
||||
|
||||
-- It will seldom offur system error, so we assume that the latest cost is correct. But it is not a correct assumption
|
||||
remove_system_error_duplicate_row AS (
|
||||
SELECT
|
||||
*,
|
||||
ROW_NUMBER() OVER (PARTITION BY transaction_order_id ORDER BY updated_datetime DESC) AS row_number_index
|
||||
|
||||
FROM remove_deleted_row
|
||||
|
||||
QUALIFY
|
||||
row_number_index = 1
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_costs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_cost_id,
|
||||
transaction_order_id,
|
||||
supplier_company_id,
|
||||
bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM remove_system_error_duplicate_row
|
||||
)
|
||||
|
||||
SELECT * FROM remove_system_error_duplicate_row
|
||||
@@ -0,0 +1,43 @@
|
||||
-- IMPORTS
|
||||
WITH group_transactions AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'group_transactions') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
group_transactions_rename AS (
|
||||
|
||||
SELECT
|
||||
group_transactions.id AS transaction_costs_brg_group_costs_id,
|
||||
group_transactions.group_id AS group_cost_id,
|
||||
group_transactions.transaction_id AS transaction_id,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM group_transactions
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_costs_brg_group_costs AS (
|
||||
|
||||
SELECT
|
||||
--ids
|
||||
transaction_costs_brg_group_costs_id,
|
||||
group_cost_id,
|
||||
transaction_id,
|
||||
|
||||
-- dimensions
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM group_transactions_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_costs_brg_group_costs
|
||||
@@ -0,0 +1,65 @@
|
||||
-- IMPORTS
|
||||
WITH documents AS (
|
||||
SELECT * FROM {{ ref('base_exchange__documents') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
documents_join_status AS (
|
||||
|
||||
SELECT
|
||||
documents.document_id,
|
||||
IFF(documents.owner_type = 'App\\Models\\Transaction', documents.owner_id, null) AS transaction_id,
|
||||
documents.document_type,
|
||||
IFF(document_type = 'CUSTOMER_PAYMENT_PROOF',
|
||||
COALESCE(status.name, documents.status::string),
|
||||
null) AS status,
|
||||
documents.approver_user_id,
|
||||
documents.approved_datetime,
|
||||
documents.deleted_datetime,
|
||||
documents.created_datetime,
|
||||
documents.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM documents
|
||||
|
||||
LEFT JOIN status
|
||||
ON (documents.status = status.id)
|
||||
|
||||
WHERE
|
||||
owner_type = 'App\\Models\\Transaction'
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_documents AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
document_id,
|
||||
transaction_id,
|
||||
approver_user_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
document_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM documents_join_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_documents
|
||||
@@ -0,0 +1,138 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_arch_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transaction_arch_logs') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
transactions_generate_transaction_log_id AS (
|
||||
SELECT
|
||||
MD5_NUMBER_LOWER64(CONCAT(transactions.transaction_id, transactions.created_datetime)) AS transaction_log_id,
|
||||
*
|
||||
|
||||
FROM transactions
|
||||
),
|
||||
|
||||
|
||||
transaction_arch_logs_union_transactions AS (
|
||||
SELECT * FROM transactions_generate_transaction_log_id
|
||||
UNION
|
||||
SELECT * FROM transaction_arch_logs
|
||||
),
|
||||
|
||||
|
||||
union_transaction_rename_column_and_column_value AS (
|
||||
|
||||
SELECT
|
||||
transaction_arch_logs_union_transactions.transaction_log_id AS transaction_order_log_id,
|
||||
transaction_arch_logs_union_transactions.transaction_id AS transaction_order_id,
|
||||
|
||||
IFF(transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Booking',
|
||||
transaction_arch_logs_union_transactions.owner_id,
|
||||
null) AS booking_id,
|
||||
|
||||
COALESCE(transaction_types.name, transaction_arch_logs_union_transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transaction_arch_logs_union_transactions.receiver_user_id AS company_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.recipient_bank_id,
|
||||
|
||||
COALESCE(payment_methods.name, transaction_arch_logs_union_transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transaction_arch_logs_union_transactions.payment_reference,
|
||||
transaction_arch_logs_union_transactions.bill_number,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_value,
|
||||
transaction_arch_logs_union_transactions.quote_value,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.quote_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_to_quote_currency_exchange_rate,
|
||||
transaction_arch_logs_union_transactions.base_tax,
|
||||
transaction_arch_logs_union_transactions.base_service_charge,
|
||||
transaction_arch_logs_union_transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transaction_arch_logs_union_transactions.status::string) AS status,
|
||||
|
||||
transaction_arch_logs_union_transactions.deleted_datetime,
|
||||
transaction_arch_logs_union_transactions.created_datetime,
|
||||
transaction_arch_logs_union_transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transaction_arch_logs_union_transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transaction_arch_logs_union_transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transaction_arch_logs_union_transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transaction_arch_logs_union_transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Booking'
|
||||
AND
|
||||
transaction_arch_logs_union_transactions.transaction_type = '1' --PAYMENT
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_order_logs AS (
|
||||
|
||||
SELECT
|
||||
--ids
|
||||
transaction_order_log_id,
|
||||
transaction_order_id,
|
||||
booking_id,
|
||||
company_id,
|
||||
recipient_bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimentions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM union_transaction_rename_column_and_column_value
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_order_logs
|
||||
@@ -0,0 +1,55 @@
|
||||
-- IMPORTS
|
||||
WITH transaction_details AS (
|
||||
SELECT * FROM {{ source('src_exchange_mysql', 'transaction_detail') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transaction_details_rename AS (
|
||||
|
||||
SELECT
|
||||
transaction_details.id AS transaction_order_product_id,
|
||||
transaction_details.transaction_id AS transaction_order_id,
|
||||
transaction_details.product_code,
|
||||
transaction_details.product_name,
|
||||
transaction_details.quantity,
|
||||
transaction_details.price,
|
||||
transaction_details.amount,
|
||||
transaction_details.deleted_at AS deleted_datetime,
|
||||
transaction_details.created_at AS created_datetime,
|
||||
transaction_details.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transaction_details
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__base_exchange__transaction_order_products AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_order_product_id,
|
||||
transaction_order_id,
|
||||
|
||||
-- dimensions
|
||||
product_code,
|
||||
product_name,
|
||||
|
||||
-- measures
|
||||
quantity,
|
||||
price,
|
||||
amount,
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transaction_details_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_exchange__transaction_order_products
|
||||
@@ -0,0 +1,116 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transactions_join_transaction_types_payment_methods_status AS (
|
||||
|
||||
SELECT
|
||||
transactions.transaction_id AS transaction_order_id,
|
||||
IFF(transactions.owner_type = 'App\\Models\\Booking', transactions.owner_id, null) AS booking_id,
|
||||
|
||||
COALESCE(transaction_types.name, transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transactions.receiver_user_id AS company_id,
|
||||
|
||||
transactions.recipient_bank_id AS bank_id,
|
||||
|
||||
COALESCE(payment_methods.name, transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transactions.payment_reference,
|
||||
transactions.bill_number,
|
||||
|
||||
transactions.base_value,
|
||||
transactions.quote_value,
|
||||
|
||||
transactions.base_currency_id,
|
||||
transactions.quote_currency_id,
|
||||
|
||||
transactions.base_to_quote_currency_exchange_rate,
|
||||
transactions.base_tax,
|
||||
transactions.base_service_charge,
|
||||
|
||||
transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transactions.status::string) AS status,
|
||||
|
||||
transactions.deleted_datetime,
|
||||
transactions.created_datetime,
|
||||
transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transactions.owner_type = 'App\\Models\\Booking'
|
||||
AND
|
||||
transactions.transaction_type = '1' --PAYMENT
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_costs AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_order_id,
|
||||
booking_id,
|
||||
company_id,
|
||||
bank_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transactions_join_transaction_types_payment_methods_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_costs
|
||||
@@ -0,0 +1,133 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_arch_logs AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transaction_arch_logs') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
transactions_generate_transaction_log_id AS (
|
||||
SELECT
|
||||
MD5_NUMBER_LOWER64(CONCAT(transactions.transaction_id, transactions.created_datetime)) AS transaction_log_id,
|
||||
*
|
||||
|
||||
FROM transactions
|
||||
),
|
||||
|
||||
|
||||
transaction_arch_logs_union_transactions AS (
|
||||
SELECT * FROM transactions_generate_transaction_log_id
|
||||
UNION
|
||||
SELECT * FROM transaction_arch_logs
|
||||
),
|
||||
|
||||
|
||||
union_transaction_rename_column_and_column_value AS (
|
||||
|
||||
SELECT
|
||||
transaction_arch_logs_union_transactions.transaction_log_id AS transaction_wallet_log_id,
|
||||
transaction_arch_logs_union_transactions.transaction_id AS transaction_wallet_id,
|
||||
|
||||
IFF(transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Wallet',
|
||||
transaction_arch_logs_union_transactions.owner_id,
|
||||
null) AS wallet_id,
|
||||
|
||||
COALESCE(transaction_types.name, transaction_arch_logs_union_transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transaction_arch_logs_union_transactions.receiver_user_id AS company_id,
|
||||
|
||||
COALESCE(payment_methods.name, transaction_arch_logs_union_transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transaction_arch_logs_union_transactions.payment_reference,
|
||||
transaction_arch_logs_union_transactions.bill_number,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_value,
|
||||
transaction_arch_logs_union_transactions.quote_value,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.quote_currency_id,
|
||||
|
||||
transaction_arch_logs_union_transactions.base_to_quote_currency_exchange_rate,
|
||||
transaction_arch_logs_union_transactions.base_tax,
|
||||
transaction_arch_logs_union_transactions.base_service_charge,
|
||||
transaction_arch_logs_union_transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transaction_arch_logs_union_transactions.status::string) AS status,
|
||||
|
||||
transaction_arch_logs_union_transactions.deleted_datetime,
|
||||
transaction_arch_logs_union_transactions.created_datetime,
|
||||
transaction_arch_logs_union_transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transaction_arch_logs_union_transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transaction_arch_logs_union_transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transaction_arch_logs_union_transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transaction_arch_logs_union_transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transaction_arch_logs_union_transactions.owner_type = 'App\\Models\\Wallet'
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_wallet_logs AS (
|
||||
|
||||
SELECT
|
||||
--ids
|
||||
transaction_wallet_log_id,
|
||||
transaction_wallet_id,
|
||||
wallet_id,
|
||||
company_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimentions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM union_transaction_rename_column_and_column_value
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_wallet_logs
|
||||
@@ -0,0 +1,110 @@
|
||||
-- IMPORTS
|
||||
WITH transactions AS (
|
||||
SELECT * FROM {{ ref('base_exchange__transactions') }}
|
||||
),
|
||||
|
||||
transaction_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__transaction_types') }}
|
||||
),
|
||||
|
||||
payment_methods AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__payment_methods') }}
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
transactions_join_transaction_types_payment_methods_currencies_status AS (
|
||||
|
||||
SELECT
|
||||
transactions.transaction_id AS transaction_wallet_id,
|
||||
IFF(transactions.owner_type = 'App\\Models\\Wallet', transactions.owner_id, null) AS wallet_id,
|
||||
|
||||
COALESCE(transaction_types.name, transactions.transaction_type::string) AS transaction_type,
|
||||
|
||||
transactions.receiver_user_id AS company_id,
|
||||
|
||||
COALESCE(payment_methods.name, transactions.payment_method::string) AS payment_method,
|
||||
|
||||
transactions.payment_reference,
|
||||
transactions.bill_number,
|
||||
|
||||
transactions.base_value,
|
||||
transactions.quote_value,
|
||||
|
||||
transactions.base_currency_id,
|
||||
transactions.quote_currency_id,
|
||||
|
||||
transactions.base_to_quote_currency_exchange_rate,
|
||||
transactions.base_tax,
|
||||
transactions.base_service_charge,
|
||||
|
||||
transactions.expired_datetime,
|
||||
|
||||
COALESCE(status.name, transactions.status::string) AS status,
|
||||
|
||||
transactions.deleted_datetime,
|
||||
transactions.created_datetime,
|
||||
transactions.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM transactions
|
||||
|
||||
LEFT JOIN transaction_types
|
||||
ON (transactions.transaction_type = transaction_types.id)
|
||||
|
||||
LEFT JOIN payment_methods
|
||||
ON (transactions.payment_method = payment_methods.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (transactions.status = status.id)
|
||||
|
||||
|
||||
WHERE
|
||||
transactions.owner_type = 'App\\Models\\Wallet'
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__transaction_wallets AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
transaction_wallet_id,
|
||||
wallet_id,
|
||||
company_id,
|
||||
base_currency_id,
|
||||
quote_currency_id,
|
||||
|
||||
-- dimensions
|
||||
transaction_type,
|
||||
payment_method,
|
||||
status,
|
||||
payment_reference,
|
||||
bill_number,
|
||||
|
||||
-- measures
|
||||
base_value,
|
||||
quote_value,
|
||||
base_to_quote_currency_exchange_rate,
|
||||
base_tax,
|
||||
base_service_charge,
|
||||
|
||||
-- date/times
|
||||
expired_datetime,
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM transactions_join_transaction_types_payment_methods_currencies_status
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__transaction_wallets
|
||||
@@ -0,0 +1,56 @@
|
||||
-- IMPORTS
|
||||
WITH user_email_verifications AS (
|
||||
SELECT * FROM {{ ref('base_exchange__user_email_verifications') }}
|
||||
),
|
||||
|
||||
users AS (
|
||||
SELECT * FROM {{ ref('base_exchange__users') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
user_email_verifications_join_users AS (
|
||||
|
||||
SELECT
|
||||
user_email_verifications.user_email_verification_id,
|
||||
|
||||
users.user_id,
|
||||
|
||||
user_email_verifications.email,
|
||||
user_email_verifications.is_completed,
|
||||
user_email_verifications.is_sent,
|
||||
user_email_verifications.created_datetime,
|
||||
user_email_verifications.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM user_email_verifications
|
||||
|
||||
LEFT JOIN users
|
||||
ON (user_email_verifications.email = users.email)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__user_email_verifications AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
user_email_verification_id,
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
email,
|
||||
is_completed,
|
||||
is_sent,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM user_email_verifications_join_users
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__user_email_verifications
|
||||
@@ -0,0 +1,69 @@
|
||||
-- IMPORTS
|
||||
WITH users AS (
|
||||
SELECT * FROM {{ ref('base_exchange__users') }}
|
||||
),
|
||||
|
||||
user_types AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__user_types') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_exchange__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
users_join_user_types_status AS (
|
||||
|
||||
SELECT
|
||||
users.user_id,
|
||||
users.name,
|
||||
users.email,
|
||||
|
||||
COALESCE(user_types.name, users.user_type::string) AS user_type,
|
||||
COALESCE(status.name, users.status::string) AS status,
|
||||
|
||||
users.deleted_datetime,
|
||||
users.created_datetime,
|
||||
users.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM users
|
||||
|
||||
LEFT JOIN user_types
|
||||
ON (users.user_type = user_types.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (users.status = status.id)
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__stg_exchange__users AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
user_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
email,
|
||||
user_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM users_join_user_types_status
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_exchange__users
|
||||
@@ -0,0 +1,21 @@
|
||||
{% docs src_shipping_mysql %}
|
||||
|
||||
Application link: https://izyim.cief-malaysia.com/
|
||||
|
||||
Data is extract from CIEF Selfhost MYSQL `portal_production`, using custom python code.
|
||||
|
||||
- `_source_loaded_at` will add into the raw data when extract
|
||||
|
||||
- Python will run the SQL in everyday 12:30AM
|
||||
|
||||
- The raw data will use copy into snowflake in 2AM everyday
|
||||
|
||||
- Depend on target.name to determin which snowflake raw schema
|
||||
|
||||
```JINJA
|
||||
{_%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{_%- else -%} DEV_CIEF_RAW_DB
|
||||
{_%- endif -%}
|
||||
```
|
||||
|
||||
{% enddocs %}
|
||||
@@ -0,0 +1,293 @@
|
||||
version: 2
|
||||
|
||||
sources:
|
||||
- name: src_shipping_mysql
|
||||
description: '{{ doc("src_shipping_mysql") }}'
|
||||
database: |
|
||||
{%- if target.name == "prod" -%} PROD_CIEF_RAW_DB
|
||||
{%- else -%} DEV_CIEF_RAW_DB
|
||||
{%- endif -%}
|
||||
schema: SHIPPING_MYSQL
|
||||
loader: custom_python_code
|
||||
loaded_at_field: _source_loaded_datetime
|
||||
freshness:
|
||||
warn_after: {count: 26, period: hour}
|
||||
error_after: {count: 48, period: hour}
|
||||
meta:
|
||||
owner: "@yam"
|
||||
model_maturity: prod
|
||||
tags:
|
||||
- exchange
|
||||
- daily
|
||||
|
||||
|
||||
tables:
|
||||
- name: activity_log
|
||||
description: Contains most table's activity log that CUD (created, updated, deleted)
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'activity_log'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: addresses
|
||||
description: Raw `addresses` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'addresses'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: announcement_segment
|
||||
description: Raw `announcement_segment` table from Snowflake
|
||||
columns:
|
||||
- name: announcement_id
|
||||
description: Primary key for 'announcement_segment'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: announcements
|
||||
description: Raw `announcements` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'announcements'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: companies
|
||||
description: Raw `companies` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'companies'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: company_connections
|
||||
description: Raw `company_connections` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'company_connections'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: company_employees
|
||||
description: Raw `company_employees` table from Snowflake
|
||||
columns:
|
||||
- name: company_module_id
|
||||
description: Primary key for 'company_employees'
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
|
||||
- name: company_modules
|
||||
description: Raw `company_modules` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'company_modules'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: connection_segments
|
||||
description: Raw `connection_segments` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'connection_segments'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: contacts
|
||||
description: Raw `contacts` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'contacts'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: container_packing_lists
|
||||
description: Raw `container_packing_lists` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'container_packing_lists'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: containers
|
||||
description: Raw `containers` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'containers'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: documents
|
||||
description: Raw `documents` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'documents'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: failed_jobs
|
||||
description: Raw `failed_jobs` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'failed_jobs'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: files
|
||||
description: Raw `files` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'files'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: order_roles
|
||||
description: Raw `order_roles` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'order_roles'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: orders
|
||||
description: Raw `orders` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'orders'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: packages
|
||||
description: Raw `packages` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'packages'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: packing_lists
|
||||
description: Raw `packing_lists` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'packing_lists'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: password_resets
|
||||
description: Raw `password_resets` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'password_resets'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: remarks
|
||||
description: Raw `remarks` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'remarks'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: schedules
|
||||
description: Raw `schedules` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'schedules'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: segment_constants
|
||||
description: Raw `segment_constants` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'segment_constants'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transaction_details
|
||||
description: Raw `transaction_details` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transaction_details'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transactions
|
||||
description: Raw `transactions` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transactions'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: transport_arrangements
|
||||
description: Raw `transport_arrangements` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'transport_arrangements'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
- name: users
|
||||
description: Raw `users` table from Snowflake
|
||||
columns:
|
||||
- name: id
|
||||
description: Primary key for 'users'
|
||||
tests:
|
||||
- unique
|
||||
- not_null
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
-- IMPORTS
|
||||
WITH orders AS (
|
||||
SELECT * FROM {{ source('src_shipping_mysql', 'orders') }}
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
orders_rename AS (
|
||||
|
||||
SELECT
|
||||
orders.id AS booking_id,
|
||||
orders.company_module_id AS sub_company_id,
|
||||
orders.reference,
|
||||
orders.reference_contract,
|
||||
orders.type AS service_type,
|
||||
orders.status,
|
||||
orders.deleted_at AS deleted_datetime,
|
||||
orders.created_at AS created_datetime,
|
||||
orders.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM orders
|
||||
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_shipping__orders AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
booking_id,
|
||||
sub_company_id,
|
||||
|
||||
-- dimensions
|
||||
reference,
|
||||
reference_contract,
|
||||
service_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM orders_rename
|
||||
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_shipping__orders
|
||||
@@ -0,0 +1,48 @@
|
||||
-- IMPORTS
|
||||
WITH companies AS (
|
||||
SELECT * FROM {{ source('src_shipping_mysql', 'companies') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
companies_rename AS (
|
||||
|
||||
SELECT
|
||||
companies.id AS parent_company_id,
|
||||
companies.name,
|
||||
companies.debtor AS autocount_id,
|
||||
companies.type AS parent_company_type,
|
||||
companies.status,
|
||||
companies.created_at AS created_datetime,
|
||||
companies.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM companies
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_shipping__parent_companies AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
parent_company_id,
|
||||
autocount_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
parent_company_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM companies_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_shipping__parent_companies
|
||||
@@ -0,0 +1,48 @@
|
||||
-- IMPORTS
|
||||
WITH company_modules AS (
|
||||
SELECT * FROM {{ source('src_shipping_mysql', 'company_modules') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
company_modules_rename AS (
|
||||
|
||||
SELECT
|
||||
company_modules.id AS sub_company_id,
|
||||
company_modules.company_id AS parent_company_id,
|
||||
company_modules.name,
|
||||
company_modules.type AS sub_company_type,
|
||||
company_modules.status,
|
||||
company_modules.created_at AS created_datetime,
|
||||
company_modules.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM company_modules
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_shipping__sub_companies AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
sub_company_id,
|
||||
parent_company_id,
|
||||
|
||||
-- dimensions
|
||||
name,
|
||||
sub_company_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM company_modules_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_shipping__sub_companies
|
||||
@@ -0,0 +1,46 @@
|
||||
-- IMPORTS
|
||||
WITH company_connections AS (
|
||||
SELECT * FROM {{ source('src_shipping_mysql', 'company_connections') }}
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
company_connections_rename AS (
|
||||
|
||||
SELECT
|
||||
company_connections.id AS sub_company_marking_connection_id,
|
||||
company_connections.invitee_id AS sub_company_id,
|
||||
company_connections.invitee_reference AS sub_company_marking_id,
|
||||
company_connections.status,
|
||||
company_connections.created_at AS created_datetime,
|
||||
company_connections.updated_at AS updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM company_connections
|
||||
),
|
||||
|
||||
|
||||
-- FINAL
|
||||
final__base_shipping__sub_company_marking_connections AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
sub_company_marking_connection_id,
|
||||
sub_company_id,
|
||||
sub_company_marking_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM company_connections_rename
|
||||
)
|
||||
|
||||
SELECT * FROM final__base_shipping__sub_company_marking_connections
|
||||
@@ -0,0 +1,65 @@
|
||||
-- IMPORT
|
||||
WITH bookings AS (
|
||||
SELECT * FROM {{ ref('base_shipping__bookings') }}
|
||||
),
|
||||
|
||||
service_types AS (
|
||||
SELECT * FROM {{ ref('seed_shipping__service_types') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_shipping__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
-- LOGIC
|
||||
bookings_map_column_values AS (
|
||||
SELECT
|
||||
bookings.booking_id,
|
||||
bookings.sub_company_id,
|
||||
bookings.reference,
|
||||
bookings.reference_contract,
|
||||
COALESCE(service_types.name, bookings.service_type::string) AS service_type,
|
||||
COALESCE(status.name, bookings.status::string) AS status,
|
||||
bookings.deleted_datetime,
|
||||
bookings.created_datetime,
|
||||
bookings.updated_datetime,
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM bookings
|
||||
|
||||
LEFT JOIN service_types
|
||||
ON (bookings.service_type = service_types.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (bookings.status = status.id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_shipping__bookings AS (
|
||||
SELECT
|
||||
-- ids
|
||||
booking_id,
|
||||
sub_company_id,
|
||||
|
||||
-- dimensions
|
||||
reference,
|
||||
reference_contract,
|
||||
service_type,
|
||||
status,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
deleted_datetime,
|
||||
created_datetime,
|
||||
updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM bookings_map_column_values
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_shipping__bookings
|
||||
@@ -0,0 +1,123 @@
|
||||
-- IMPORTS
|
||||
WITH parent_companies AS (
|
||||
SELECT * FROM {{ ref('base_shipping__parent_companies') }}
|
||||
),
|
||||
|
||||
sub_companies AS (
|
||||
SELECT * FROM {{ ref('base_shipping__sub_companies') }}
|
||||
),
|
||||
|
||||
sub_company_marking_connections AS (
|
||||
SELECT * FROM {{ ref('base_shipping__sub_company_marking_connections') }}
|
||||
),
|
||||
|
||||
parent_company_types AS (
|
||||
SELECT * FROM {{ ref('seed_shipping__parent_company_types') }}
|
||||
WHERE category = 'RENAME'
|
||||
),
|
||||
|
||||
sub_company_types AS (
|
||||
SELECT * FROM {{ ref('seed_shipping__sub_company_types') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
status AS (
|
||||
SELECT * FROM {{ ref('seed_shipping__status') }}
|
||||
WHERE category = 'DEFAULT'
|
||||
),
|
||||
|
||||
|
||||
-- LOGIC
|
||||
parent_companies_join_sub_companies AS (
|
||||
SELECT
|
||||
parent_companies.parent_company_id AS parent_company_id,
|
||||
parent_companies.autocount_id,
|
||||
parent_companies.name AS parent_company_name,
|
||||
parent_companies.parent_company_type AS company_type,
|
||||
parent_companies.status,
|
||||
parent_companies.created_datetime AS parent_company_created_datetime,
|
||||
parent_companies.updated_datetime AS parent_company_updated_datetime,
|
||||
|
||||
sub_companies.sub_company_id AS sub_company_id,
|
||||
sub_companies.name AS sub_company_name,
|
||||
sub_companies.sub_company_type AS business_type,
|
||||
sub_companies.created_datetime AS sub_company_created_datetime,
|
||||
sub_companies.updated_datetime AS sub_company_updated_datetime
|
||||
|
||||
FROM parent_companies
|
||||
|
||||
LEFT JOIN sub_companies
|
||||
ON (parent_companies.parent_company_id = sub_companies.sub_company_id)
|
||||
),
|
||||
|
||||
parent_companies_and_sub_companies_map_constants AS (
|
||||
SELECT
|
||||
parent_companies_join_sub_companies.parent_company_id,
|
||||
parent_companies_join_sub_companies.autocount_id,
|
||||
parent_companies_join_sub_companies.parent_company_name,
|
||||
|
||||
COALESCE(company_types.name, parent_companies_join_sub_companies.company_type::string) AS company_type,
|
||||
|
||||
COALESCE(status.name, parent_companies_join_sub_companies.status::string) AS status,
|
||||
|
||||
parent_companies_join_sub_companies.parent_company_created_datetime,
|
||||
parent_companies_join_sub_companies.parent_company_updated_datetime,
|
||||
parent_companies_join_sub_companies.sub_company_id,
|
||||
parent_companies_join_sub_companies.sub_company_name,
|
||||
|
||||
COALESCE(business_type.name, parent_companies_join_sub_companies.business_type::string) AS business_type,
|
||||
|
||||
parent_companies_join_sub_companies.sub_company_created_datetime,
|
||||
parent_companies_join_sub_companies.sub_company_updated_datetime,
|
||||
|
||||
sub_company_marking_connections.sub_company_marking_id,
|
||||
|
||||
'{{ modules.datetime.datetime.now(modules.pytz.timezone("Asia/Kuala_Lumpur")) }}' AS _dbt_ran_datetime
|
||||
|
||||
FROM parent_companies_join_sub_companies
|
||||
|
||||
LEFT JOIN sub_company_marking_connections
|
||||
ON (parent_companies_join_sub_companies.sub_company_id = sub_company_marking_connections.sub_company_id)
|
||||
|
||||
LEFT JOIN parent_company_types AS company_types
|
||||
ON (parent_companies_join_sub_companies.company_type = company_types.id)
|
||||
|
||||
LEFT JOIN sub_company_types AS business_type
|
||||
ON (parent_companies_join_sub_companies.business_type = business_type.id)
|
||||
|
||||
LEFT JOIN status
|
||||
ON (parent_companies_join_sub_companies.status = status.id)
|
||||
),
|
||||
|
||||
-- FINAL
|
||||
final__stg_shipping__parent_and_sub_companies AS (
|
||||
|
||||
SELECT
|
||||
-- ids
|
||||
parent_company_id,
|
||||
autocount_id,
|
||||
sub_company_id,
|
||||
sub_company_marking_id,
|
||||
|
||||
-- dimensions
|
||||
status,
|
||||
parent_company_name,
|
||||
sub_company_name,
|
||||
company_type,
|
||||
business_type,
|
||||
|
||||
-- measures
|
||||
|
||||
-- date/times
|
||||
parent_company_created_datetime,
|
||||
parent_company_updated_datetime,
|
||||
sub_company_created_datetime,
|
||||
sub_company_updated_datetime,
|
||||
|
||||
-- metadata
|
||||
_dbt_ran_datetime
|
||||
|
||||
FROM parent_companies_and_sub_companies_map_constants
|
||||
)
|
||||
|
||||
SELECT * FROM final__stg_shipping__parent_and_sub_companies
|
||||
Reference in New Issue
Block a user