Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-26 Thread Jonathan Hurley

---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review186259
---


Ship it!




Ship It!

- Jonathan Hurley


On Sept. 26, 2017, 9:24 a.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 26, 2017, 9:24 a.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  79c021c369 
>   
> ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
>  63e3840a5d 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/2/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-26 Thread Dmitro Lisnichenko

---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/
---

(Updated Sept. 26, 2017, 4:24 p.m.)


Review request for Ambari, Jonathan Hurley and Nate Cole.


Changes
---

Rebased on latest 2.6, added test coverage. Unit tests are running


Bugs: AMBARI-21998
https://issues.apache.org/jira/browse/AMBARI-21998


Repository: ambari


Description
---

During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
constraints are definned without name in older Ambari versions, and then 
altered by name in UpgadeCatalogs/newer DDLs.

For example:
Ambari 2.2.2
https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
{code} UNIQUE (ldap_user, user_name));{code}
Ambari-2.4.0
https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
{code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}

As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale unique 
constraint with default name is not deleted.
That will reproduce on Postgres for any upgrade path that includes these 
versions.

{code}ambari=# \d+ users
Table "ambari.users"
Column |Type | Modifiers
  | Storage  | Description
---+-++--+-
user_id   | integer | not null  
 | plain|
principal_id  | bigint  | not null  
 | plain|
ldap_user | integer | not null default 0
 | plain|
user_name | character varying(255)  | not null  
 | extended |
create_time   | timestamp without time zone | default now() 
 | plain|
user_password | character varying(255)  |   
 | extended |
active| integer | not null default 1
 | plain|
active_widget_layouts | character varying(1024) | default NULL::character 
varying| extended |
user_type | character varying(255)  | default 
'LOCAL'::character varying | extended |
Indexes:
"users_pkey" PRIMARY KEY, btree (user_id)
"unq_users_0" UNIQUE, btree (user_name, user_type)
"users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
Foreign-key constraints:
"fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
adminprincipal(principal_id)
Referenced by:
TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
REFERENCES users(user_id)
Has OIDs: no

{code}

Now we have two constraints here
"unq_users_0" UNIQUE, btree (user_name, user_type) 
"users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG


Diffs (updated)
-

  
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
 79c021c369 
  
ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
 63e3840a5d 


Diff: https://reviews.apache.org/r/62413/diff/2/

Changes: https://reviews.apache.org/r/62413/diff/1-2/


Testing
---

tests on live cluster


Thanks,

Dmitro Lisnichenko



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-20 Thread Nate Cole


> On Sept. 19, 2017, 4:44 p.m., Jonathan Hurley wrote:
> > Do you plan to include the ability to extract constraint names from tables 
> > in this review? It's marked currently as preview...
> 
> Dmitro Lisnichenko wrote:
> Yes. It's not a very simple thing, just wanted to make sure that we want 
> it (otherwise, current patch would be enough)

Do we have to extract them?  Can we drop them all then recreate them with the 
right names?


- Nate


---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review185731
---


On Sept. 19, 2017, 12:17 p.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 19, 2017, 12:17 p.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  afd3d1d6a5 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/1/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-19 Thread Dmitro Lisnichenko


> On Sept. 19, 2017, 11:44 p.m., Jonathan Hurley wrote:
> > Do you plan to include the ability to extract constraint names from tables 
> > in this review? It's marked currently as preview...

Yes. It's not a very simple thing, just wanted to make sure that we want it 
(otherwise, current patch would be enough)


- Dmitro


---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review185731
---


On Sept. 19, 2017, 7:17 p.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 19, 2017, 7:17 p.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  afd3d1d6a5 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/1/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-19 Thread Nate Cole

---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review185755
---


Ship it!




Needs a test.  Other than Jonathan's comment, LGTM.

- Nate Cole


On Sept. 19, 2017, 12:17 p.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 19, 2017, 12:17 p.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  afd3d1d6a5 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/1/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-19 Thread Jonathan Hurley

---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review185731
---



Do you plan to include the ability to extract constraint names from tables in 
this review? It's marked currently as preview...

- Jonathan Hurley


On Sept. 19, 2017, 12:17 p.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 19, 2017, 12:17 p.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  afd3d1d6a5 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/1/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>



Re: Review Request 62413: (Preview) Ambari upgrade don't delete stale constraints

2017-09-19 Thread Dmitro Lisnichenko

---
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/62413/#review185701
---




ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
Lines 200 (patched)


This PK constraint has been given a name in DDL for 2.6



ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
Lines 208 (patched)


That is a minimal hotfix for current issue. I have to hardcode generated 
constraint name, because we have no utility to extract existing constraints for 
table.
As a more general fix, I'm trying to implement utility methods that would 
fetch 
- name(s) of unique constraints that target given columns
- name of primary key constraint for table
- names of foreign key constraints for table


- Dmitro Lisnichenko


On Sept. 19, 2017, 7:17 p.m., Dmitro Lisnichenko wrote:
> 
> ---
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/62413/
> ---
> 
> (Updated Sept. 19, 2017, 7:17 p.m.)
> 
> 
> Review request for Ambari, Jonathan Hurley and Nate Cole.
> 
> 
> Bugs: AMBARI-21998
> https://issues.apache.org/jira/browse/AMBARI-21998
> 
> 
> Repository: ambari
> 
> 
> Description
> ---
> 
> During  Ambari upgrade from 2.2.2 to 2.5 I discovered that some UNIQUE 
> constraints are definned without name in older Ambari versions, and then 
> altered by name in UpgadeCatalogs/newer DDLs.
> 
> For example:
> Ambari 2.2.2
> https://github.com/apache/ambari/blob/branch-2.2.2/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
> {code} UNIQUE (ldap_user, user_name));{code}
> Ambari-2.4.0
> https://github.com/apache/ambari/blob/branch-2.4/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql#L288
> {code}  CONSTRAINT UNQ_users_0 UNIQUE (user_name, user_type)){code}
> 
> As a result, during upgrade from Ambari 2.2.2 to Ambari 2.5.0, the stale 
> unique constraint with default name is not deleted.
> That will reproduce on Postgres for any upgrade path that includes these 
> versions.
> 
> {code}ambari=# \d+ users
> Table "ambari.users"
> Column |Type | Modifiers  
> | Storage  | Description
> ---+-++--+-
> user_id   | integer | not null
>| plain|
> principal_id  | bigint  | not null
>| plain|
> ldap_user | integer | not null default 0  
>| plain|
> user_name | character varying(255)  | not null
>| extended |
> create_time   | timestamp without time zone | default now()   
>| plain|
> user_password | character varying(255)  | 
>| extended |
> active| integer | not null default 1  
>| plain|
> active_widget_layouts | character varying(1024) | default NULL::character 
> varying| extended |
> user_type | character varying(255)  | default 
> 'LOCAL'::character varying | extended |
> Indexes:
> "users_pkey" PRIMARY KEY, btree (user_id)
> "unq_users_0" UNIQUE, btree (user_name, user_type)
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name)
> Foreign-key constraints:
> "fk_users_principal_id" FOREIGN KEY (principal_id) REFERENCES 
> adminprincipal(principal_id)
> Referenced by:
> TABLE "members" CONSTRAINT "fk_members_user_id" FOREIGN KEY (user_id) 
> REFERENCES users(user_id)
> Has OIDs: no
> 
> {code}
> 
> Now we have two constraints here
> "unq_users_0" UNIQUE, btree (user_name, user_type) 
> "users_ldap_user_key" UNIQUE, btree (ldap_user, user_name) <- WRONG
> 
> 
> Diffs
> -
> 
>   
> ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
>  afd3d1d6a5 
> 
> 
> Diff: https://reviews.apache.org/r/62413/diff/1/
> 
> 
> Testing
> ---
> 
> tests on live cluster
> 
> 
> Thanks,
> 
> Dmitro Lisnichenko
> 
>