Skip to content

Mohith 209 organizations table#212

Open
MohithS04 wants to merge 5 commits into
mainfrom
Mohith--209-Organizations-table
Open

Mohith 209 organizations table#212
MohithS04 wants to merge 5 commits into
mainfrom
Mohith--209-Organizations-table

Conversation

@MohithS04
Copy link
Copy Markdown

Hello Pallavi, Can you once check the newly created ddl_organizations_1_.sql table

@MohithS04 MohithS04 self-assigned this Apr 14, 2026
Renamed column 'is_collaborator' to 'is_collaborative', added 'is_contributing' column, updated values based on 'org_type', and added a constraint and index for contributing organizations.
@MohithS04
Copy link
Copy Markdown
Author

Since, I am unable to create a Test case Table and pork it in script-library/tests. So, I've written the Test cases in an existing PR.
Test Cases for Organization Table Migration

Test 1: rename applied
DO $$
BEGIN
ASSERT NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'virginia_dev_saayam_rdbms'
AND table_name = 'organizations'
AND column_name = 'is_collaborator'
), 'T1: legacy column is_collaborator still present.';

ASSERT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_schema = 'virginia_dev_saayam_rdbms'
      AND table_name   = 'organizations'
      AND column_name  = 'is_collaborative'
      AND data_type    = 'boolean'
), 'T1: is_collaborative missing or wrong type.';

END $$;

Test 2: new column added
DO $$
BEGIN
ASSERT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'virginia_dev_saayam_rdbms'
AND table_name = 'organizations'
AND column_name = 'is_contributing'
AND data_type = 'boolean'
), 'T2: is_contributing missing or wrong type.';
END $$;

Test 3: PK, FK, and ENUM types intact
DO $$
BEGIN
ASSERT EXISTS (
SELECT 1 FROM information_schema.table_constraints
WHERE table_schema = 'virginia_dev_saayam_rdbms'
AND table_name = 'organizations'
AND constraint_type = 'PRIMARY KEY'
), 'T3: primary key missing.';

ASSERT EXISTS (
    SELECT 1 FROM information_schema.table_constraints
    WHERE table_schema = 'virginia_dev_saayam_rdbms'
      AND table_name   = 'organizations'
      AND constraint_type = 'FOREIGN KEY'
), 'T3: foreign key missing.';

ASSERT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'org_type_enum'), 'T3: org_type_enum missing.';
ASSERT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'org_size_enum'), 'T3: org_size_enum missing.';

END $$;

Test 4: insert + round-trip via new column names
BEGIN;
INSERT INTO virginia_dev_saayam_rdbms.organizations
(org_name, org_type, org_size, is_collaborative, is_contributing)
VALUES ('TEST_ORG_RENAME', 'non_profit', 'small', TRUE, NULL);

DO $$
DECLARE v_collab BOOLEAN; v_contrib BOOLEAN; v_id VARCHAR(255);
BEGIN
SELECT org_id, is_collaborative, is_contributing
INTO v_id, v_collab, v_contrib
FROM virginia_dev_saayam_rdbms.organizations
WHERE org_name = 'TEST_ORG_RENAME';

ASSERT v_collab IS TRUE, 'T4: is_collaborative did not persist.';
ASSERT v_contrib IS NULL, 'T4: is_contributing did not persist NULL.';
ASSERT v_id LIKE 'ORG-00-%', 'T4: org_id pattern broken.';

END $$;
ROLLBACK;

Test 5: trigger generate_org_id still fires
BEGIN;
INSERT INTO virginia_dev_saayam_rdbms.organizations
(org_name, org_type, org_size, is_collaborative, is_contributing)
VALUES ('TEST_ORG_TRIGGER', 'for_profit', 'medium', FALSE, TRUE);

DO $$
DECLARE v_id VARCHAR(255);
BEGIN
SELECT org_id INTO v_id
FROM virginia_dev_saayam_rdbms.organizations
WHERE org_name = 'TEST_ORG_TRIGGER';

ASSERT v_id IS NOT NULL, 'T5: trigger did not populate org_id.';
ASSERT v_id ~ '^ORG-00-\d{3}-\d{3}-\d{3}$', 'T5: org_id format invalid.';

END $$;
ROLLBACK;

Test 6: all boolean combinations + NULL accepted
BEGIN;
INSERT INTO virginia_dev_saayam_rdbms.organizations
(org_name, org_type, org_size, is_collaborative, is_contributing) VALUES
('TEST_ORG_TT', 'for_profit', 'small', TRUE, TRUE),
('TEST_ORG_TF', 'for_profit', 'small', TRUE, FALSE),
('TEST_ORG_FT', 'for_profit', 'small', FALSE, TRUE),
('TEST_ORG_FF', 'for_profit', 'small', FALSE, FALSE),
('TEST_ORG_NN', 'non_profit', 'small', NULL, NULL);

DO $$
DECLARE v_count INT;
BEGIN
SELECT COUNT(*) INTO v_count
FROM virginia_dev_saayam_rdbms.organizations
WHERE org_name LIKE 'TEST_ORG_%';
ASSERT v_count = 5, 'T6: not all boolean combinations accepted.';
END $$;
ROLLBACK;

Test 7: existing CHECK constraints still enforced
DO $$
BEGIN
BEGIN
INSERT INTO virginia_dev_saayam_rdbms.organizations (org_name, web_url)
VALUES ('TEST_BAD_URL', 'ftp://nope');
RAISE EXCEPTION 'T7: web_url CHECK not enforced.';
EXCEPTION WHEN check_violation THEN NULL;
END;

BEGIN
    INSERT INTO virginia_dev_saayam_rdbms.organizations (org_name, email)
    VALUES ('TEST_BAD_EMAIL', 'no-at');
    RAISE EXCEPTION 'T7: email CHECK not enforced.';
EXCEPTION WHEN check_violation THEN NULL;
END;

BEGIN
    INSERT INTO virginia_dev_saayam_rdbms.organizations (org_name, org_rating)
    VALUES ('TEST_BAD_RATING', 99);
    RAISE EXCEPTION 'T7: org_rating CHECK not enforced.';
EXCEPTION WHEN check_violation THEN NULL;
END;

END $$;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant