Skip to content

Commit e59519b

Browse files
committed
update config gen query to take dataset name
1 parent 9324f6d commit e59519b

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

crates/configuration/src/config2.sql

+12-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ WITH column_data AS (
88
c.column_name AS name,
99
JSON_OBJECT('ScalarType',
1010
case LOWER(c.data_type)
11+
when 'bool' then 'boolean'
1112
when 'boolean' then 'boolean'
1213
when 'int16' then 'smallint'
1314
when 'smallint' then 'smallint'
@@ -26,10 +27,14 @@ WITH column_data AS (
2627
when 'json' then 'json'
2728
when 'jsonb' then 'jsonb'
2829
when 'date' then 'date'
29-
when 'time with time zone' then 'time with time zone'
30-
when 'time without time zone' then 'time without time zone'
31-
when 'timestamp with time zone' then 'timestamp with time zone'
32-
when 'timestamp without time zone' then 'timestamp without time zone'
30+
when 'timetz' then 'timetz'
31+
when 'time' then 'time'
32+
when 'timestamptz' then 'timestamptz'
33+
when 'timestamp' then 'timestamp'
34+
when 'time with time zone' then 'timetz'
35+
when 'time without time zone' then 'time'
36+
when 'timestamp with time zone' then 'timestamptz'
37+
when 'timestamp without time zone' then 'timestamp'
3338
when 'uuid' then 'uuid'
3439
else 'any'
3540
end
@@ -41,7 +46,7 @@ WITH column_data AS (
4146
ON c.table_catalog = t.table_catalog
4247
AND c.table_schema = t.table_schema
4348
AND c.table_name = t.table_name
44-
WHERE t.table_schema = 'chinook_sample'
49+
WHERE t.table_schema = 'HASURA_DATABASE_SCHEMA_PLACEHOLDER'
4550
),
4651
columns_struct AS (
4752
SELECT
@@ -77,7 +82,7 @@ relationship_data AS (
7782
AND c.constraint_schema = rc.constraint_schema
7883
AND c.constraint_name = rc.constraint_name
7984
JOIN HASURA_DATABASE_NAME_PLACEHOLDER.INFORMATION_SCHEMA.KEY_COLUMN_USAGE as fc ON c.constraint_name = fc.constraint_name
80-
WHERE t.table_schema = 'chinook_sample' AND c.constraint_type = 'FOREIGN KEY'
85+
WHERE t.table_schema = 'HASURA_DATABASE_SCHEMA_PLACEHOLDER' AND c.constraint_type = 'FOREIGN KEY'
8186
GROUP BY t.table_name, table_catalog, table_schema, constraint_name, rc.table_name, fc.column_name, rc.column_name
8287
),
8388
relationship_struct AS (
@@ -108,7 +113,7 @@ unique_constraint_data AS (
108113
AND c.table_name = t.table_name
109114
JOIN HASURA_DATABASE_NAME_PLACEHOLDER.INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE as cc
110115
ON c.constraint_name = cc.constraint_name
111-
WHERE t.table_schema = 'chinook_sample'
116+
WHERE t.table_schema = 'HASURA_DATABASE_SCHEMA_PLACEHOLDER'
112117
AND c.constraint_type in ('PRIMARY KEY', 'UNIQUE')
113118
AND cc.constraint_catalog = c.constraint_catalog
114119
AND cc.constraint_schema = c.constraint_schema

crates/configuration/src/version1.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub async fn configure(
133133
.query(project_id, QueryRequest::new(types_query))
134134
.await
135135
.unwrap();
136-
dbg!(&types_row);
136+
// dbg!(&types_row);
137137

138138
let types_query_response = types_row.query_response().clone();
139139
let empty_tablerow = vec![TableRow::default()];
@@ -174,7 +174,10 @@ pub async fn configure(
174174
let config_query_string_with_database_name: String =
175175
config_query_string.replace("HASURA_DATABASE_NAME_PLACEHOLDER", database_name.as_str()); //TODO(PY): what is a safe name to provide as a variable name?
176176

177-
let tables_query_request = QueryRequest::new(config_query_string_with_database_name);
177+
let config_query_with_schema_name = config_query_string_with_database_name
178+
.replace("HASURA_DATABASE_SCHEMA_PLACEHOLDER", dataset_id);
179+
180+
let tables_query_request = QueryRequest::new(config_query_with_schema_name);
178181

179182
let tables_result = bigquery_client
180183
.job()
@@ -183,6 +186,7 @@ pub async fn configure(
183186
.unwrap();
184187

185188
let table_rows = tables_result.query_response().clone();
189+
// dbg!(&table_rows);
186190

187191
let mut tables_info = TablesInfo::empty();
188192

@@ -384,7 +388,7 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
384388

385389
for type_item in type_names {
386390
let type_name = match type_item.name.as_str().to_lowercase().as_str() {
387-
"boolean" => "boolean",
391+
"bool" | "boolean" => "boolean",
388392
"int16" | "smallint" => "smallint",
389393
"int" | "int32" | "integer" => "integer",
390394
"int64" | "bigint" => "bigint",
@@ -398,10 +402,10 @@ fn get_scalar_types(type_names: &Vec<TypeItem>, schema_name: String) -> database
398402
"json" => "json",
399403
"jsonb" => "jsonb",
400404
"date" => "date",
401-
"time with time zone" => "time with time zone",
402-
"time without time zone" => "time without time zone",
403-
"timestamp with time zone" => "timestamp with time zone",
404-
"timestamp without time zone" => "timestamp without time zone",
405+
"timetz" | "time with time zone" => "timetz",
406+
"time" | "time without time zone" => "time",
407+
"timestamptz" | "timestamp with time zone" => "timestamptz",
408+
"timestamp" | "timestamp without time zone" => "timestamp",
405409
"uuid" => "uuid",
406410
_ => "any",
407411
};

0 commit comments

Comments
 (0)