GithubHelp home page GithubHelp logo

Resolving relationships about pgsync HOT 8 CLOSED

arvindkhadri avatar arvindkhadri commented on August 28, 2024
Resolving relationships

from pgsync.

Comments (8)

toluaina avatar toluaina commented on August 28, 2024

Can you please post your database schema here. Maybe just the product and category table definition.

from pgsync.

arvindkhadri avatar arvindkhadri commented on August 28, 2024

Sharing the SQL statements that were used to create the tables.

CREATE TABLE public.product (
    id bigint NOT NULL,
    name public.citext NOT NULL,
    created_date timestamp with time zone DEFAULT now() NOT NULL,
    category_id bigint NOT NULL,
    brand_id bigint,
    hsn bigint DEFAULT 0 NOT NULL,
    active boolean DEFAULT true NOT NULL,
    description text
);

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_brand_id_fkey FOREIGN KEY (brand_id) REFERENCES public.category(id) ON UPDATE RESTRICT ON DELETE RESTRICT;

ALTER TABLE ONLY public.product
    ADD CONSTRAINT product_category_id_fkey FOREIGN KEY (category_id) REFERENCES public.category(id) ON UPDATE RESTRICT ON DELETE RESTRICT;

CREATE TABLE public.category (
    id bigint NOT NULL,
    name public.citext NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    parent_id bigint,
    image_url text,
    type text DEFAULT 'CATEGORY'::text NOT NULL,
    description text
);

from pgsync.

toluaina avatar toluaina commented on August 28, 2024

I think your category table is missing a unique constraint. I don't want to assume here.
Can you provide the schema so I can recreate the tables? Possibly the entire schema
Your existing schema assuming it has a unique constraint works ok.

from pgsync.

arvindkhadri avatar arvindkhadri commented on August 28, 2024

I have an unique constraint, rather two on that table.

ALTER TABLE ONLY public.category
    ADD CONSTRAINT category_name_key UNIQUE (name);

ALTER TABLE ONLY public.category
    ADD CONSTRAINT category_name_type_key UNIQUE (name, type);


ALTER TABLE ONLY public.category
    ADD CONSTRAINT category_pkey PRIMARY KEY (id);

Sorry that these were missed.

from pgsync.

toluaina avatar toluaina commented on August 28, 2024

Can you send the full database schema?
I'm simply unable to reproduce your scenario. The category is not null when I do this so maybe I'm still missing something in your full schema.

pg_dump -d <dbname> -s

from pgsync.

arvindkhadri avatar arvindkhadri commented on August 28, 2024

https://gist.github.com/arvindkhadri/e3afec66793e6a74ad00c463ca25cadd That has the complete schema.

from pgsync.

toluaina avatar toluaina commented on August 28, 2024

So I've created an s.sql from this db schema

psql -d mydb < s.sql

added some records

INSERT INTO category (id, name, parent_id, image_url, type, description) VALUES (1, 'cat_1', 1, 'http://foo1.bar', 'type_x', 'description 1');
INSERT INTO category (id, name, parent_id, image_url, type, description) VALUES (2, 'cat_2', 2, 'http://foo2.bar', 'type_y', 'description 2');
INSERT INTO category (id, name, parent_id, image_url, type, description) VALUES (3, 'cat_3', 3, 'http://foo3.bar', 'type_z', 'description 3');

INSERT INTO product (id, name, category_id, brand_id, hsn, active, description) VALUES (1, 'product_1', 1, 1, 123, true, 'product description 1');
INSERT INTO product (id, name, category_id, brand_id, hsn, active, description) VALUES (2, 'product_2', 2, 2, 456, false, 'product description 2');
INSERT INTO product (id, name, category_id, brand_id, hsn, active, description) VALUES (3, 'product_3', 3, 3, 789, true, 'product description 3');

pgsync -c s.json

and I get this doc data
are you sure there are related category data for those products in your database?

from pgsync.

toluaina avatar toluaina commented on August 28, 2024

Closing as no reply on this.

from pgsync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.