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

sql: Ecto compatibility #33441

Open
11 of 18 tasks
BramGruneir opened this issue Jan 2, 2019 · 21 comments
Open
11 of 18 tasks

sql: Ecto compatibility #33441

BramGruneir opened this issue Jan 2, 2019 · 21 comments
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) meta-issue Contains a list of several other issues. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@BramGruneir
Copy link
Member

BramGruneir commented Jan 2, 2019

This is a list of issues found with Ecto (Elixir).
Note that most of these are not required to get Ecto working, but each of these can be a potential roadblock when migrating an existing app to cockroach.

Jira issue: CRDB-4690

@BramGruneir BramGruneir added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Jan 2, 2019
@BramGruneir BramGruneir mentioned this issue Jan 2, 2019
16 tasks
@knz knz added meta-issue Contains a list of several other issues. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) labels Jan 3, 2019
@DavidOliver
Copy link

@awoods187
Copy link
Contributor

@DavidOliver this will be in 20.1 and you can see it in this beta (https://www.cockroachlabs.com/docs/releases/v20.1.0-beta.2.html)

@fire
Copy link

fire commented Apr 28, 2020

Note that #24897 is resolved.

Not possible to change stored query on a view, must drop the view and recreate #24897

@fire
Copy link

fire commented Apr 28, 2020

#32917 Must do foreign keys in three separate migrations (add column, add an index on that column, add the constraint)

#32917 in a pr stage.

@RoachietheSupportRoach
Copy link
Collaborator

Zendesk ticket #5257 has been linked to this issue.

@DavidOliver
Copy link

#32917 is resolved.

@rafiss
Copy link
Collaborator

rafiss commented May 9, 2020

note that named SAVEPOINT support will also be included in 20.1

@tlvenn
Copy link
Contributor

tlvenn commented Jul 13, 2020

It should be noted that with CDB 20.1 all the major issues have been fixed but one as soon as you are running tests. This is fixed on master but it has yet to be released.

Additionally:

@rafiss
Copy link
Collaborator

rafiss commented Jul 13, 2020

#50858 is closed and the fix will also be included in the next 20.1 release.

Thanks for filing those two new issues!

@escobera
Copy link

escobera commented Nov 13, 2020

I found a problem when creating schemas with Ecto.Migration.

This code just hangs after the execution and the next migration never runs. I'm testing on 20.2

defmodule ProcessosApi.Repo.Migrations.CreateMySchema do
  use Ecto.Migration

  def change do
    execute "CREATE SCHEMA myschema"
  end
end

I don't know if this is the correct place to report this. If not just lemme know and I'll move to the correct place.

Thanks in advance!

@rafiss rafiss added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 12, 2021
@lessless
Copy link

In light of the upcoming webinar - what are the plans for getting proper compatibility with Ecto?

@ghost
Copy link

ghost commented May 18, 2021

In light of the upcoming webinar - what are the plans for getting proper compatibility with Ecto?

We’ve been running in production for a number of clients for a while (+ 6 months) now (erlang solutions). Using the Postgres driver and can’t think of any issues.

Might be time to close this issue out unless there’s something we’ve been missing. Migrations issues etc are gone now.

@lessless
Copy link

Thanks for feedback @bryanhuntesl

@lessless
Copy link

@escobera won't you mind sharing your connection settings, please? I have few problems:

The first one is with SSL - I’m running into an {:tls_alert, {:handshake_failure, 'TLS client: In state wait_cert_cr at ssl_handshake.erl:1990 generated CLIENT ALERT: Fatal - Handshake Failure\n {bad_cert,hostname_check_failed}'}} with

ssl_opts: [
  verify: :verify_peer,
  cacertfile: '/Users/lessless/.postgresql/root.crt',
]

The second one with specifying a cluster name? If I disable an SSL I’m getting following error FATAL 08004 (sqlserver_rejected_establishment_of_sqlconnection) codeParamsRoutingFailed: missing cluster name in connection string

I took connection params from “Connection parameters” tab and database value there seems to be a combination from cluster name and a database name database = superfun-superfun-448.defaultdb but that doesn't work.

@lessless
Copy link

lessless commented Aug 15, 2021

@bryanhuntesl given that I ignore SSL host validation and create a database by hand I'm encountering a problem when running migrations:

no match of right hand side value: {:error, %Postgrex.Error{connection_id: 0, message: nil, postgres: %{code: :syntax_error, detail: "source SQL:\nLOCK TABLE \"schema_migrations\" IN SHARE UPDATE EXCLUSIVE MODE\n^", file: "lexer.go", line: "215", message: "at or near \"lock\": syntax error", pg_code: "42601", routine: "Error", severity: "ERROR"}, query: "LOCK TABLE \"schema_migrations\" IN SHARE UPDATE EXCLUSIVE MODE"}}

Here is a reproduction of this query from the cockroach shell

superfun@free-tier4.aws-us-west-2.cockroachlabs.cloud:26257/defaultdb> LOCK TABLE "schema_migrations" IN SHARE UPDATE EXCLUSIVE MODE;
invalid syntax: statement ignored: at or near "lock": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
LOCK TABLE "schema_migrations" IN SHARE UPDATE EXCLUSIVE MODE
^
superfun@free-tier4.aws-us-west-2.cockroachlabs.cloud:26257/defaultdb> ^D
ERROR: invalid syntax
Failed running "SQL

@timothyvanderaerden
Copy link

@lessless to configure with SSL:

database: "superfun-superfun-448.defaultdb",
ssl: true,
ssl_opts: [
  cacertfile: "cc-ca.crt"
]

More info: https://hexdocs.pm/postgrex/Postgrex.html#start_link/1-ssl-client-authentication

To run migrations, migration_lock should be disabled since CockroachDB doesn't support table locking (as far as I know):

migration_lock: false

More info: https://hexdocs.pm/ecto_sql/Ecto.Migration.html#module-repo-configuration

@erszcz
Copy link

erszcz commented Oct 21, 2021

I confirm getting the error that @lessless mentioned above:

** (MatchError) no match of right hand side value: {:error, %Postgrex.Error{connection_id: 0, message: nil, postgres: %{code: :syntax_error, detail: "source SQL:\nLOCK TABLE \"schema_migrations\" IN SHARE UPDATE EXCLUSIVE MODE\n^", file: "lexer.go", line: "215", message: "at or near \"lock\": syntax error", pg_code: "42601", routine: "Error", severity: "ERROR"}, query: "LOCK TABLE \"schema_migrations\" IN SHARE UPDATE EXCLUSIVE MODE"}}

Running migrations used to work fine - this started happening after an upgrade from ecto_sql 3.5.4 to 3.7.1.

@ghost
Copy link

ghost commented Oct 21, 2021 via email

@rafiss
Copy link
Collaborator

rafiss commented Oct 21, 2021

@erszcz As @timothyvanderaerden mentioned, CockroachDB does not support table locking.

It seems like ecto_sql has added some functionality that uses table locking.

Can you set migration_lock: false? https://hexdocs.pm/ecto_sql/Ecto.Migration.html#module-repo-configuration

@erszcz
Copy link

erszcz commented Oct 21, 2021

Thanks @bryanhuntesl and @rafiss! Indeed, migration_lock: false solves the problem on ecto_sql 3.7.1.

@benonymus
Copy link

benonymus commented Feb 10, 2023

Hey,

I am dabbling with moving to cockroachDB.

When I am running some historical migrations, this seems to not work:

    alter table(:session_chats) do
      modify :session_id, references(:sessions, on_delete: :delete_all),
        from: references(:sessions, on_delete: :nothing)
    end

The error:

alter table session_chats
** (Postgrex.Error) ERROR 42710 (duplicate_object) duplicate constraint name: "session_chats_session_id_fkey"

Are these not supported? Or how would I need to rewrite them?

These work on regular postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) meta-issue Contains a list of several other issues. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests