这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions server/src-lib/Hasura/RQL/DDL/Relationship.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 9 additions & 20 deletions server/tests-py/queries/v1/track_table/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,25 @@ args:
args:
sql: |
create table author(
id serial primary key,
id serial primary key,
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);
9 changes: 3 additions & 6 deletions server/tests-py/queries/v1/track_table/teardown.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
type: bulk
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;
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions server/tests-py/test_v1_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,10 @@ def test_track_untrack_table(self, hge_ctx):
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
Expand Down