Skip to content

Commit

Permalink
refactor(core): change primary keys in user, user_roles and roles tab…
Browse files Browse the repository at this point in the history
…les (#5374)
  • Loading branch information
prajjwalkumar17 authored Jul 19, 2024
1 parent 476aed5 commit b51c8e1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 6 deletions.
6 changes: 3 additions & 3 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

roles (id) {
roles (role_id) {
id -> Int4,
#[max_length = 64]
role_name -> Varchar,
Expand Down Expand Up @@ -1251,7 +1251,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

user_roles (id) {
user_roles (user_id, merchant_id) {
id -> Int4,
#[max_length = 64]
user_id -> Varchar,
Expand All @@ -1275,7 +1275,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

users (id) {
users (user_id) {
id -> Int4,
#[max_length = 64]
user_id -> Varchar,
Expand Down
6 changes: 3 additions & 3 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

roles (id) {
roles (role_id) {
id -> Int4,
#[max_length = 64]
role_name -> Varchar,
Expand Down Expand Up @@ -1249,7 +1249,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

user_roles (id) {
user_roles (user_id, merchant_id) {
id -> Int4,
#[max_length = 64]
user_id -> Varchar,
Expand All @@ -1273,7 +1273,7 @@ diesel::table! {
use diesel::sql_types::*;
use crate::enums::diesel_exports::*;

users (id) {
users (user_id) {
id -> Int4,
#[max_length = 64]
user_id -> Varchar,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`
ALTER TABLE users DROP CONSTRAINT users_pkey;

ALTER TABLE users
ADD PRIMARY KEY (id);
12 changes: 12 additions & 0 deletions migrations/2024-07-19-095541_change_primary_key_for_users/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Your SQL goes here
-- The below query will lock the users table
-- Running this query is not necessary on higher environments
-- as the application will work fine without these queries being run
-- This query should be run after the new version of application is deployed
ALTER TABLE users DROP CONSTRAINT users_pkey;

-- Use the `user_id` columns as primary key
-- These are already unique, not null column
-- So this query should not fail for not null or duplicate value reasons
ALTER TABLE users
ADD PRIMARY KEY (user_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`
ALTER TABLE user_roles DROP CONSTRAINT user_roles_pkey;

ALTER TABLE user_roles
ADD PRIMARY KEY (id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Your SQL goes here
-- The below query will lock the user_roles table
-- Running this query is not necessary on higher environments
-- as the application will work fine without these queries being run
-- This query should be run after the new version of application is deployed
ALTER TABLE user_roles DROP CONSTRAINT user_roles_pkey;

-- Use the `user_id, merchant_id` columns as primary key
-- These are already unique, not null columns
-- So this query should not fail for not null or duplicate value reasons
ALTER TABLE user_roles
ADD PRIMARY KEY (user_id, merchant_id);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file should undo anything in `up.sql`
ALTER TABLE roles DROP CONSTRAINT roles_pkey;

ALTER TABLE roles
ADD PRIMARY KEY (id);
12 changes: 12 additions & 0 deletions migrations/2024-07-19-100936_change_primary_key_for_roles/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Your SQL goes here
-- The below query will lock the user_roles table
-- Running this query is not necessary on higher environments
-- as the application will work fine without these queries being run
-- This query should be run after the new version of application is deployed
ALTER TABLE roles DROP CONSTRAINT roles_pkey;

-- Use the `role_id` column as primary key
-- These are already unique, not null column
-- So this query should not fail for not null or duplicate value reasons
ALTER TABLE roles
ADD PRIMARY KEY (role_id);

0 comments on commit b51c8e1

Please sign in to comment.