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

CHE-4372; add unique constraing for factory name + user #4521

Merged
merged 8 commits into from
Mar 23, 2017

Conversation

mshaposhnik
Copy link
Contributor

What does this PR do?

Makes factory name mandatory on database level (auto generated if not set by user)

What issues does this PR fix or reference?

#4372

Changelog

Factory name made mandatory on database level

Release Notes

n/a

Docs PR

N/A

@@ -133,8 +141,12 @@ public Factory updateFactory(Factory update, Set<FactoryImage> images) throws Co
ServerException {
requireNonNull(update);
final AuthorImpl creator = factoryDao.getById(update.getId()).getCreator();
FactoryImpl updateImpl = new FactoryImpl(update, images);
if (isNullOrEmpty(updateImpl.getName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better not to generate new name when update doesn't contain it. Let's set old name when it is null or empty in update.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case you cant re-assign the name to another factory. I don't know if it's good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you can't re-assign the name? You can send name in update then name will be updated. Or you can miss it, then old name will be used (but not generated new)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it looks stupid, if you deleting the factory name on Dashb, and it returns back after update :). But seems others are with you, so ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So seems it must not be generated on update at all.

-- from Codenvy S.A..
--

CREATE UNIQUE INDEX index_name_plus_userid ON che_factory (user_id, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index_name_plus_userid -> index_che_factory_name_user_id

--

UPDATE che_factory
SET name = concat('f', right(id, 9)) WHERE name IS NULL OR name = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Script name does not match the content

@codenvy-ci
Copy link

Build # 2256 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/2256/ to view the results.

@codenvy-ci
Copy link


-- Make names unique for the same user, e.g if there is more than one factory with same name and user,
-- leave first one and rename others.
WITH dupes AS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this migration on codenvy tables before we move factory to che?
Because it's weird to see such a postgresql specific migration in che, while che doesn't have factories yet.
Moreover it allows to define unique constraint next to che_factory declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can move naming uniques into 1.1 in codenvy, then 1.2 will do the migration, and costraint will be just in che_factory table definition.

@mshaposhnik mshaposhnik merged commit 6adfe61 into factory_migration Mar 23, 2017
@mshaposhnik mshaposhnik deleted the CHE-4372 branch March 23, 2017 13:16
@codenvy-ci
Copy link

Build # 2267 - FAILED

Please check console output at https://ci.codenvycorp.com/job/che-pullrequests-build/2267/ to view the results.

@JamesDrummond JamesDrummond added this to the 5.6.0 milestone Mar 30, 2017
@JamesDrummond JamesDrummond mentioned this pull request Apr 2, 2017
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants