server: fix bug when renaming table with manual relationships (#5806)

https://github.com/hasura/graphql-engine/pull/5806
This commit is contained in:
Karthikeyan Chinnakonda 2020-10-28 15:51:53 +05:30 committed by GitHub
parent ebe6990c45
commit c63801b573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 16 deletions

View File

@ -80,6 +80,7 @@ This release contains the [PDV refactor (#4111)](https://github.com/hasura/graph
- server: change `created_at` column type from `timestamp` to `timestamptz` for scheduled triggers tables (fix #5722)
- server: allow configuring timeouts for actions (fixes #4966)
- server: accept only non-negative integers for batch size and refetch interval (close #5653) (#5759)
- server: fix bug which arised when renaming a table which had a manual relationship defined (close #4158)
- server: limit the length of event trigger names (close #5786)
**NOTE:** If you have event triggers with names greater than 42 chars, then you should update their names to avoid running into Postgres identifier limit bug (#5786)
- server: validate remote schema queries (fixes #4143)

View File

@ -171,7 +171,10 @@ updateObjRelDef qt rn (oldQT, newQT) = do
let newDef = case oldDef of
RUFKeyOn _ -> oldDef
RUManual (RelManualConfig dbQT rmCols) ->
let updQT = bool oldQT newQT $ oldQT == dbQT
-- here `dbQT` is the remote table, we only need to
-- make changes in the relationship definition when the
-- remote table has been renamed
let updQT = bool dbQT newQT $ oldQT == dbQT
in RUManual $ RelManualConfig updQT rmCols
liftTx $ updateRel qt rn $ toJSON newDef
@ -190,7 +193,10 @@ updateArrRelDef qt rn (oldQT, newQT) = do
in RUManual $ RelManualConfig updQT rmCols
liftTx $ updateRel qt rn $ toJSON newDef
where
getUpdQT dbQT = bool oldQT newQT $ oldQT == dbQT
-- here `dbQT` is the remote table, we only need to
-- make changes in the relationship definition when the
-- remote table has been renamed
getUpdQT dbQT = bool dbQT newQT $ oldQT == dbQT
-- | update fields in premissions
updatePermFlds :: (MonadTx m, CacheRM m)

View File

@ -2,7 +2,7 @@
#Array relationship
- description: Create array relationship using manual method
url: /v1/query
status: 200
status: 200
response:
message: success
query:
@ -30,6 +30,45 @@
name: articles
new_name: articles_array
#Rename tables associated with the relationship
- description: Rename the remote table
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER TABLE article RENAME TO articles;
- description: Rename the original table/view
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER TABLE author_view RENAME TO authors_view;
- description: Rename tables back to the original name for the teardown process
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER view authors_view RENAME TO author_view;
- description: Rename tables back to the original name for the teardown process
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER TABLE articles RENAME TO article;
#Drop relationship
- description: Drop object relationship
url: /v1/query

View File

@ -1,7 +1,7 @@
#Create object relationship
- description: Create object relationship using manual method
url: /v1/query
status: 200
status: 200
response:
message: success
query:
@ -12,9 +12,9 @@
using:
manual_configuration:
remote_table: author_view
column_mapping:
column_mapping:
author_id : id
- description: Nested select on article
url: /v1/query
status: 200
@ -48,7 +48,7 @@
- name: author
columns:
- id
- name
- name
#Rename object relationship
- description: Rename object relationship author to author_obj
@ -98,7 +98,43 @@
- name: author_obj
columns:
- id
- name
- name
- description: Rename the remote table
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER TABLE author_view RENAME TO authors_view;
- description: Rename the original table/view
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER TABLE article_view RENAME TO articles_view;
- description: Rename tables back to the original name for the teardown process
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER VIEW authors_view RENAME TO author_view;
- description: Rename tables back to the original name for the teardown process
url: /v1/query
status: 200
query:
type: run_sql
args:
sql: |
ALTER VIEW articles_view RENAME TO article_view;
#Drop object relationship
- description: Drop object relationship

View File

@ -6,7 +6,7 @@ args:
args:
sql: |
create table author(
id serial primary key,
id serial primary key,
name text unique,
remarks text
);
@ -72,7 +72,7 @@ args:
- type: run_sql
args:
sql: |
CREATE VIEW hge_tests.resident_view AS
CREATE VIEW hge_tests.resident_view AS
SELECT id, name FROM hge_tests.resident
- type: track_table
args:
@ -99,7 +99,7 @@ args:
- type: run_sql
args:
sql: |
CREATE VIEW hge_tests.address_view AS
CREATE VIEW hge_tests.address_view AS
SELECT id, door_no, city, resident_id FROM hge_tests.address
- type: track_table
args:
@ -128,11 +128,11 @@ args:
- content: Sample article content 3
title: Article 3
author_id: 2
#Insert resident table data
- type: insert
args:
table:
table:
name: resident
schema: hge_tests
objects:
@ -144,13 +144,13 @@ args:
#Insert address table data
- type: insert
args:
table:
table:
name: address
schema: hge_tests
objects:
- door_no: 12-21
street: Madhapur
city: Hyderabad
street: Madhapur
city: Hyderabad
resident_id: 1
- door_no: 11-19
street: Koramangala