mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
This commit is contained in:
parent
b5b2fe6851
commit
5514b40de2
@ -179,6 +179,10 @@ objRelP2Setup qt (RelDef rn ru _) = do
|
||||
[(consName, refsn, reftn, colMapping)] -> do
|
||||
let deps = [ SchemaDependency (SOTableObj qt $ TOCons consName) "fkey"
|
||||
, SchemaDependency (SOTableObj qt $ TOCol cn) "using_col"
|
||||
-- this needs to be added explicitly to handle the remote table
|
||||
-- being untracked. In this case, neither the using_col nor
|
||||
-- the constraint name will help.
|
||||
, SchemaDependency (SOTable refqt) "remote_table"
|
||||
]
|
||||
refqt = QualifiedTable refsn reftn
|
||||
void $ askTabInfo refqt
|
||||
@ -284,6 +288,10 @@ arrRelP2Setup qt (RelDef rn ru _) = do
|
||||
[(consName, mapping)] -> do
|
||||
let deps = [ SchemaDependency (SOTableObj refqt $ TOCons consName) "remote_fkey"
|
||||
, SchemaDependency (SOTableObj refqt $ TOCol refCol) "using_col"
|
||||
-- we don't need to necessarily track the remote table like we did in
|
||||
-- case of obj relationships as the remote table is indirectly
|
||||
-- tracked by tracking the constraint name and 'using_col'
|
||||
, SchemaDependency (SOTable refqt) "remote_table"
|
||||
]
|
||||
return (RelInfo rn ArrRel (map swap mapping) refqt False, deps)
|
||||
_ -> throw400 ConstraintError
|
||||
|
@ -10,32 +10,21 @@ args:
|
||||
name text unique,
|
||||
remarks text
|
||||
);
|
||||
|
||||
|
||||
#Create resident table
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
create table article(
|
||||
id serial primary key,
|
||||
title text,
|
||||
author_id integer references author(id)
|
||||
);
|
||||
CREATE TABLE hge_tests.resident (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
age INTEGER NOT NULL
|
||||
)
|
||||
|
||||
#Insert values
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
);
|
||||
insert into author (name)
|
||||
values
|
||||
('Author 1'),
|
||||
('Author 2')
|
||||
|
||||
#Insert values
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
('Author 2');
|
||||
insert into hge_tests.resident (name,age)
|
||||
values
|
||||
('Resident 1', 23),
|
||||
('Resident 2', 31)
|
||||
('Resident 2', 31);
|
||||
|
@ -4,9 +4,6 @@ args:
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
drop table author
|
||||
|
||||
- type: run_sql
|
||||
args:
|
||||
sql: |
|
||||
drop table hge_tests.resident
|
||||
drop table hge_tests.resident;
|
||||
drop table article;
|
||||
drop table author;
|
||||
|
@ -0,0 +1,80 @@
|
||||
- description: Track tables and relationships
|
||||
url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
- message: success
|
||||
- message: success
|
||||
- message: success
|
||||
- message: success
|
||||
query:
|
||||
type: bulk
|
||||
args:
|
||||
- type: track_table
|
||||
args:
|
||||
name: author
|
||||
- type: track_table
|
||||
args:
|
||||
name: article
|
||||
- type: create_object_relationship
|
||||
args:
|
||||
name: author
|
||||
table: article
|
||||
using:
|
||||
foreign_key_constraint_on: author_id
|
||||
- type: create_array_relationship
|
||||
args:
|
||||
name: articles
|
||||
table: author
|
||||
using:
|
||||
foreign_key_constraint_on:
|
||||
table: article
|
||||
column: author_id
|
||||
|
||||
- description: untrack author
|
||||
url: /v1/query
|
||||
status: 400
|
||||
response:
|
||||
path: "$.args"
|
||||
error: "cannot drop due to the following dependent objects : relationship article.author"
|
||||
code: "dependency-error"
|
||||
query:
|
||||
type: untrack_table
|
||||
args:
|
||||
table:
|
||||
name: author
|
||||
|
||||
- description: untrack article
|
||||
url: /v1/query
|
||||
status: 400
|
||||
response:
|
||||
path: "$.args"
|
||||
error: "cannot drop due to the following dependent objects : relationship author.articles"
|
||||
code: "dependency-error"
|
||||
query:
|
||||
type: untrack_table
|
||||
args:
|
||||
table:
|
||||
name: article
|
||||
|
||||
- description: untrack author with cascade
|
||||
url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
message: success
|
||||
query:
|
||||
type: untrack_table
|
||||
args:
|
||||
table:
|
||||
name: author
|
||||
cascade: true
|
||||
|
||||
- description: untrack article
|
||||
url: /v1/query
|
||||
status: 200
|
||||
response:
|
||||
message: success
|
||||
query:
|
||||
type: untrack_table
|
||||
args:
|
||||
table:
|
||||
name: article
|
@ -449,6 +449,10 @@ class TestTrackTables(DefaultTestQueries):
|
||||
check_query_f(hge_ctx, self.dir() + '/track_untrack_table.yaml')
|
||||
hge_ctx.may_skip_test_teardown = True
|
||||
|
||||
def test_track_untrack_table_with_deps(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/track_untrack_table_deps.yaml')
|
||||
hge_ctx.may_skip_test_teardown = True
|
||||
|
||||
def test_track_untrack_table_non_public_schema(self, hge_ctx):
|
||||
check_query_f(hge_ctx, self.dir() + '/track_untrack_table_non_public_schema.yaml')
|
||||
hge_ctx.may_skip_test_teardown = True
|
||||
|
Loading…
Reference in New Issue
Block a user