----------------------------------------------------------- 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 > >