Issue
Recently I came across an issue with a client, that has many solutions, but none was easy. This application uses Postgresql DB and there are two environments: dev and prod.
At some point someone thought that it was a good idea to delete one of the tables (module_people_new) from prod without taking care of the FK and other issues that it could carry. Luckily, it was a module that was not very coupled with the application so the application kept working just fine.
When I started working with this application, some functions were failing with integrity errors, so I found out it was because of that. I tried the same functions in dev and saw that they were working, so the table was there.
Postgresql table description
Now, I was wondering if there is a way to "recover" that table in prod, from the information I have in dev. I know that I could just get the table description and built a create query from there, but I was wondering if there is a more "direct" way. With table description I mean:
db-> \d+ module_people_new
Table "public.module_people_new"
Column | Type | Modifiers | Storage | Stats target | Description
---------------------------+--------------------------+-----------+----------+--------------+-------------
id | integer | not null | plain | |
created_at | timestamp with time zone | not null | plain | |
updated_at | timestamp with time zone | not null | plain | |
first_name | character varying(255) | not null | extended | |
last_name | character varying(255) | not null | extended | |
user_id | integer | not null | plain | |
. . .
Indexes:
"module_people_pkey" PRIMARY KEY, btree (id)
. . .
Check constraints:
. . .
Foreign-key constraints:
"module_user_id_4d9d48da00e81837_fk_module_user_id" FOREIGN KEY (user_id) REFERENCES module_user(id) DEFERRABLE INITIALLY DEFERRED
. . .
Another possibility
The application is a Django app, so I also have the migrations, but I'm afraid there have been a few changes that may have affected that table and others related. But, maybe I could use that. The only problem is that I don't want to copy-paste the migration and simply apply it, cross-finger and hope it works. I know that you can get the SQL query from Django ORM queries, maybe there is a way to get the query from a migration as well?
Thanks a lot :)
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)