|
6 | 6 |
|
7 | 7 | {{
|
8 | 8 | config(
|
9 |
| - target_database='TestDB_Secondary', |
| 9 | + target_database='secondary_db', |
10 | 10 | target_schema='dbo',
|
11 | 11 | unique_key='id',
|
12 | 12 |
|
|
37 | 37 |
|
38 | 38 |
|
39 | 39 | class TestCrossDB:
|
| 40 | + def create_secondary_db(self, project): |
| 41 | + create_sql = """ |
| 42 | + DECLARE @col NVARCHAR(256) |
| 43 | + SET @col = (SELECT CONVERT (varchar(256), SERVERPROPERTY('collation'))); |
| 44 | +
|
| 45 | + IF NOT EXISTS (SELECT * FROM sys.databases WHERE name='secondary_db') |
| 46 | + BEGIN |
| 47 | + EXEC ('CREATE DATABASE secondary_db COLLATE ' + @col) |
| 48 | + END |
| 49 | + """ |
| 50 | + |
| 51 | + with get_connection(project.adapter): |
| 52 | + project.adapter.execute( |
| 53 | + create_sql.format(database=project.database), |
| 54 | + fetch=True, |
| 55 | + ) |
| 56 | + |
| 57 | + def cleanup_secondary_database(self, project): |
| 58 | + drop_sql = "DROP DATABASE IF EXISTS secondary_db" |
| 59 | + with get_connection(project.adapter): |
| 60 | + project.adapter.execute( |
| 61 | + drop_sql.format(database=project.database), |
| 62 | + fetch=True, |
| 63 | + ) |
| 64 | + |
40 | 65 | def cleanup_primary_table(self, project):
|
41 | 66 | drop_sql = "DROP TABLE IF EXISTS {database}.mysource.claims"
|
42 | 67 | with get_connection(project.adapter):
|
@@ -98,7 +123,7 @@ def create_primary_table(self, project):
|
98 | 123 |
|
99 | 124 | def create_secondary_schema(self, project):
|
100 | 125 | src_query = """
|
101 |
| - USE [TestDB_Secondary] |
| 126 | + USE [secondary_db] |
102 | 127 | EXEC ('CREATE SCHEMA {schema}')
|
103 | 128 | """
|
104 | 129 | with get_connection(project.adapter):
|
@@ -130,12 +155,16 @@ def snapshots(self):
|
130 | 155 | return {"claims_snapshot.sql": snapshot_sql}
|
131 | 156 |
|
132 | 157 | def test_cross_db_snapshot(self, project):
|
| 158 | + self.create_secondary_db(project) |
| 159 | + |
133 | 160 | self.cleanup_primary_table(project)
|
134 | 161 | self.cleanup_snapshot_table(project)
|
135 | 162 |
|
136 | 163 | self.create_source_schema(project)
|
137 | 164 | self.create_primary_table(project)
|
138 |
| - # self.create_secondary_schema(project) |
139 | 165 | run_dbt(["snapshot"])
|
140 | 166 | self.update_primary_table(project)
|
141 | 167 | run_dbt(["snapshot"])
|
| 168 | + |
| 169 | + self.cleanup_snapshot_table(project) |
| 170 | + self.cleanup_secondary_database(project) |
0 commit comments