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

[YSQL] Implement UNIQUE constraint #1022

Closed
mbautin opened this issue Mar 16, 2019 · 1 comment
Closed

[YSQL] Implement UNIQUE constraint #1022

mbautin opened this issue Mar 16, 2019 · 1 comment
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature

Comments

@mbautin
Copy link
Collaborator

mbautin commented Mar 16, 2019

E.g. needed by Django support -- a default new project schema requires it:

11:10 $ ./manage.py migrate
/home/mikhail/test/django/venv/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.NotSupportedError: UNIQUE constraint not supported yet
LINE 1: ...jango_content_type_app_label_model_76bd3d3b_uniq" UNIQUE ("a...
                                                             ^
HINT:  Please contact YugaByte for its release schedule.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 514, in database_forwards
    getattr(new_model._meta, self.option_name, set()),
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 360, in alter_unique_together
    self.execute(self._create_unique_sql(model, columns))
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/mikhail/test/django/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.NotSupportedError: UNIQUE constraint not supported yet
LINE 1: ...jango_content_type_app_label_model_76bd3d3b_uniq" UNIQUE ("a...
                                                             ^
HINT:  Please contact YugaByte for its release schedule.

@mbautin mbautin self-assigned this Mar 16, 2019
@kmuthukk kmuthukk added the kind/enhancement This is an enhancement of an existing feature label Mar 17, 2019
@mbautin mbautin assigned frozenspider and unassigned mbautin Mar 18, 2019
yugabyte-ci pushed a commit that referenced this issue Apr 23, 2019
Summary:
We already have UNIQUE index support, and all work necessary for UNIQUE constraint support was
essentially done by @robert in #955
All that was left to do was to enable UNIQUE constraint in grammar and add test coverage.

Test Plan: ./yb_build.sh release --java-test org.yb.pgsql.TestPgUniqueConstraint

Reviewers: mikhail, neil, robert

Reviewed By: robert

Subscribers: neha, mihnea, robert, yql

Differential Revision: https://phabricator.dev.yugabyte.com/D6458
@frozenspider
Copy link
Contributor

Implemented in e283667

@kmuthukk kmuthukk added the area/ysql Yugabyte SQL (YSQL) label Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants