-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add check for not valid constraints #362
Comments
I have a question regarding this issue; may I ask it? Should I add content to the final class named Validators in the validation package of the pg-index-health-model module and write test code for it? |
Hi @BLoHny
No, you shouldn't Please take a look at There I briefly described things you need to do to implement a new check |
would this satisfy your request? SELECT
t.relname AS table_name, -- Name of the table
c.conname AS constraint_name, -- Name of the constraint
c.contype AS constraint_type -- Type of the constraint
FROM pg_catalog.pg_constraint c
JOIN pg_catalog.pg_class t ON t.oid = c.conrelid
WHERE NOT c.convalidated; -- Constraints that have not yet been validated |
It's almost ready) I think we need to keep filtering on Also all sql queries have to be schema-aware I use SQLFluff for analysing sql queries syntax and codestyle P.S. Then in Java code we need to implement a new base class for database constraints. |
After understanding it, I applied it. Which sql query more satisfies your request? SELECT
t.relname AS table_name, -- Name of the table
c.conname AS constraint_name, -- Name of the constraint
c.contype AS constraint_type -- Type of the constraint
FROM
pg_catalog.pg_constraint c
JOIN pg_catalog.pg_class t ON t.oid = c.conrelid
JOIN pg_catalog.pg_namespace n ON n.oid = t.relnamespace
WHERE
NOT c.convalidated -- Constraints that have not yet been validated
AND c.contype IN ('c', 'f') -- Focus on check and foreign key constraints
AND n.nspname = :schema_name_param::text; -- Make the query schema-aware or SELECT
t.relname AS table_name, -- Name of the table
c.conname AS constraint_name, -- Name of the constraint
c.contype AS constraint_type, -- Type of the constraint
CASE c.contype
WHEN 'c' THEN 'Check constraint'
WHEN 'f' THEN 'Foreign key constraint'
WHEN 'p' THEN 'Primary key constraint'
WHEN 'u' THEN 'Unique constraint'
WHEN 't' THEN 'Constraint trigger'
WHEN 'x' THEN 'Exclusion constraint'
ELSE 'Unknown'
END AS constraint_type_description, -- Description of the constraint type
n.nspname AS schema_name -- Name of the schema
FROM
pg_catalog.pg_constraint c
JOIN
pg_catalog.pg_class t ON c.conrelid = t.oid
JOIN
pg_catalog.pg_namespace n ON t.relnamespace = n.oid
WHERE
n.nspname = :schema_name_param::text -- Recognizing the schema
AND NOT c.convalidated -- Constraints that have not yet been validated
AND c.contype IN ('c', 'f'); -- Focusing on specific types of constraints |
I like the first variant more |
I have a question. |
Yes, we should. First of all you need to add a new element to Line 25 in 2470e90
|
Hi @BLoHny, Query was tested with create schema demo;
CREATE TABLE demo.c1001_1
(
id integer GENERATED ALWAYS AS IDENTITY NOT NULL,
parent_id integer NOT NULL,
value integer NOT NULL,
CONSTRAINT c1001_1_pk PRIMARY KEY (id)
);
ALTER TABLE demo.c1001_1 ADD CONSTRAINT c1001_1_fk FOREIGN KEY (parent_id) REFERENCES public.c1001_1(id) NOT VALID;
ALTER TABLE demo.c1001_1 ADD CONSTRAINT c1001_1_chk CHECK ( value > 0 ) NOT VALID;
create sequence if not exists demo.accounts_seq;
create table if not exists demo.accounts (
id bigint not null primary key default nextval('demo.accounts_seq'),
client_id bigint not null,
account_number varchar(50) not null unique,
account_balance numeric(22,2) not null default 0,
deleted boolean not null default false);
create sequence if not exists demo.clients_seq;
create table if not exists demo.clients (
id bigint not null primary key default nextval('demo.clients_seq'),
last_name varchar(255) not null,
first_name varchar(255) not null,
middle_name varchar(255),
info jsonb);
alter table if exists demo.accounts
add constraint c_accounts_fk_client_id foreign key (client_id) references demo.clients (id); |
Hi @BLoHny, |
#363 |
Ok! Drop a comment in that issue and I'll assign it to you |
See article https://habr.com/ru/articles/800121/
The text was updated successfully, but these errors were encountered: