Skip to content

Adds index on _Role name property #3586

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

Merged

Conversation

natanrolnik
Copy link
Contributor

@natanrolnik natanrolnik commented Mar 1, 2017

In order to avoid having different _Role objects with the same name, adding an index on the name property of _Role is necessary.

In apps migrated from Parse.com, the index ensuring uniqueness on _Role names already existed. This issue only happens on new Parse Server apps.

Fixes #3579

.then(() => this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']))
.catch(error => {
logger.warn('Unable to ensure uniqueness for role name: ', error);
return Promise.reject(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

i think you can safely just return the error here instead of returning a rejected error, but don't take my word for it.....

Copy link
Contributor

Choose a reason for hiding this comment

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

for continuations of errors, the pattern should be throw error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@acinader
Copy link
Contributor

acinader commented Mar 3, 2017

@natanrolnik do the unit tests pass locally? when i run locally, the same tests fail as on travis and they are related to roles and schemas....suspicious.... ;)

  1. SchemaController creates non-custom classes which include relation field
  2. schemas creates _User schema when server starts
  3. schemas responds with a list of schemas after creating objects

@natanrolnik natanrolnik force-pushed the dont-allow-duplicate-roles branch from 5b5bfff to e755d34 Compare March 4, 2017 16:49
@facebook-github-bot
Copy link

@natanrolnik updated the pull request - view changes

In order to avoid having different _Role objects with the same name, adding an index on the name property of _Role is necessary.

Fixes parse-community#3579
@natanrolnik natanrolnik force-pushed the dont-allow-duplicate-roles branch from e755d34 to c3e3584 Compare March 4, 2017 19:15
@facebook-github-bot
Copy link

@natanrolnik updated the pull request - view changes

.then(() => this.adapter.ensureUniqueness('_Role', requiredRoleFields, ['name']))
.catch(error => {
logger.warn('Unable to ensure uniqueness for role name: ', error);
return Promise.reject(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

for continuations of errors, the pattern should be throw error

@facebook-github-bot
Copy link

@natanrolnik updated the pull request - view changes

@@ -494,7 +494,8 @@ describe('SchemaController', () => {

it('creates non-custom classes which include relation field', done => {
config.database.loadSchema()
.then(schema => schema.addClassIfNotExists('_Role', {}))
Copy link
Contributor

@flovilmart flovilmart Mar 4, 2017

Choose a reason for hiding this comment

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

this should still be OK no? or does the addClassIfNoExists fail if the class exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I was expecting as well, but I was getting Class _Role already exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could add a test, though, that makes sure addClassIfNotExists returns the existing schema, instead of an error, if the class already exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok that's good the

@facebook-github-bot
Copy link

@natanrolnik updated the pull request - view changes

@flovilmart
Copy link
Contributor

@acinader, it's looking good for me. Anything on your side?

@acinader
Copy link
Contributor

acinader commented Mar 4, 2017

👍 lgtm!

@acinader acinader merged commit 9bfa0c6 into parse-community:master Mar 4, 2017
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.

4 participants