Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): change primary keys in user, user_roles and roles tables #5374

Merged
merged 7 commits into from
Jul 19, 2024
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);
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);
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);
Loading