Created
May 30, 2022 21:30
-
-
Save azzumed/d7fd56f2f6e3fc3f5255ff96e11ed900 to your computer and use it in GitHub Desktop.
Postgre user and user_contacts tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ---------------------------- | |
-- Table structure for user_contacts | |
-- ---------------------------- | |
DROP TABLE IF EXISTS "public"."user_contacts"; | |
CREATE TABLE "public"."user_contacts" ( | |
"id" int8 NOT NULL DEFAULT nextval('user_contacts_id_seq'::regclass), | |
"user_id" int8 NOT NULL, | |
"contact_user_id" int8 NOT NULL | |
) | |
; | |
-- ---------------------------- | |
-- Records of user_contacts | |
-- ---------------------------- | |
INSERT INTO "public"."user_contacts" VALUES (1, 1, 2); | |
INSERT INTO "public"."user_contacts" VALUES (2, 1, 3); | |
INSERT INTO "public"."user_contacts" VALUES (3, 1, 4); | |
INSERT INTO "public"."user_contacts" VALUES (5, 1, 6); | |
INSERT INTO "public"."user_contacts" VALUES (6, 1, 7); | |
INSERT INTO "public"."user_contacts" VALUES (7, 1, 8); | |
INSERT INTO "public"."user_contacts" VALUES (8, 2, 1); | |
INSERT INTO "public"."user_contacts" VALUES (9, 2, 3); | |
INSERT INTO "public"."user_contacts" VALUES (10, 2, 4); | |
INSERT INTO "public"."user_contacts" VALUES (11, 3, 1); | |
INSERT INTO "public"."user_contacts" VALUES (12, 3, 2); | |
INSERT INTO "public"."user_contacts" VALUES (13, 3, 4); | |
INSERT INTO "public"."user_contacts" VALUES (14, 3, 5); | |
INSERT INTO "public"."user_contacts" VALUES (15, 3, 6); | |
INSERT INTO "public"."user_contacts" VALUES (16, 3, 7); | |
INSERT INTO "public"."user_contacts" VALUES (17, 4, 1); | |
INSERT INTO "public"."user_contacts" VALUES (18, 4, 2); | |
INSERT INTO "public"."user_contacts" VALUES (19, 4, 3); | |
INSERT INTO "public"."user_contacts" VALUES (20, 4, 5); | |
INSERT INTO "public"."user_contacts" VALUES (21, 4, 6); | |
INSERT INTO "public"."user_contacts" VALUES (4, 1, 5); | |
INSERT INTO "public"."user_contacts" VALUES (23, 9, 1); | |
-- ---------------------------- | |
-- Table structure for users | |
-- ---------------------------- | |
DROP TABLE IF EXISTS "public"."users"; | |
CREATE TABLE "public"."users" ( | |
"id" int8 NOT NULL DEFAULT nextval('users_id_seq'::regclass), | |
"name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL, | |
"email" varchar(255) COLLATE "pg_catalog"."default" NOT NULL | |
) | |
; | |
-- ---------------------------- | |
-- Records of users | |
-- ---------------------------- | |
INSERT INTO "public"."users" VALUES (1, 'a', 'a'); | |
INSERT INTO "public"."users" VALUES (2, 'q', 'q'); | |
INSERT INTO "public"."users" VALUES (3, 'q', 'w'); | |
INSERT INTO "public"."users" VALUES (4, 'q', 'e'); | |
INSERT INTO "public"."users" VALUES (5, 'q', 'r'); | |
INSERT INTO "public"."users" VALUES (6, 'q', 't'); | |
INSERT INTO "public"."users" VALUES (7, 'w', 'y'); | |
INSERT INTO "public"."users" VALUES (8, 'w', 'u'); | |
INSERT INTO "public"."users" VALUES (9, 'w', 'i'); | |
-- ---------------------------- | |
-- Primary Key structure for table user_contacts | |
-- ---------------------------- | |
ALTER TABLE "public"."user_contacts" ADD CONSTRAINT "user_contacts_pkey" PRIMARY KEY ("id"); | |
-- ---------------------------- | |
-- Uniques structure for table users | |
-- ---------------------------- | |
ALTER TABLE "public"."users" ADD CONSTRAINT "users_email_unique" UNIQUE ("email"); | |
-- ---------------------------- | |
-- Primary Key structure for table users | |
-- ---------------------------- | |
ALTER TABLE "public"."users" ADD CONSTRAINT "users_pkey" PRIMARY KEY ("id"); | |
-- ---------------------------- | |
-- Foreign Keys structure for table user_contacts | |
-- ---------------------------- | |
ALTER TABLE "public"."user_contacts" ADD CONSTRAINT "user_contacts_contact_user_id_foreign" FOREIGN KEY ("contact_user_id") REFERENCES "public"."users" ("id") ON DELETE CASCADE ON UPDATE CASCADE; | |
ALTER TABLE "public"."user_contacts" ADD CONSTRAINT "user_contacts_user_id_foreign" FOREIGN KEY ("user_id") REFERENCES "public"."users" ("id") ON DELETE CASCADE ON UPDATE CASCADE; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment