Giter VIP home page Giter VIP logo

exandra's People

Contributors

heroinbob avatar himanshu21git avatar noaccos avatar rbino avatar restlessronin avatar vinniefranco avatar whatyouhide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

exandra's Issues

Tuples

At the moment there is no way to declare a tuple in the schemas, probably a custom type (like Exandra.Set) is necessary

Cannot create schema_migrations

Describe the bug
I added the exandra to the deps {:exandra, "~> 0.6"}
Then I made a repo with config

defmodule Chats.XandraRepo do
  use Ecto.Repo,
    otp_app: :chats,
    adapter: Exandra
end

And generated a migration.

But when I run mix ecto.migrate I get the following error

[error] Could not create schema migrations table. This error usually happens due to the following:

  * The database does not exist
  * The "schema_migrations" table, which Ecto uses for managing
    migrations, was defined by another library
  * There is a deadlock while migrating (such as using concurrent
    indexes with a migration_lock)

To fix the first issue, run "mix ecto.create" for the desired MIX_ENV.

To address the second, you can run "mix ecto.drop" followed by
"mix ecto.create", both for the desired MIX_ENV. Alternatively you may
configure Ecto to use another table and/or repository for managing
migrations:

I see my keyspace in cqlsh so the database definitely exists
What can I do to fix it?

Support `RENAME` in migrations

Currently, for this migration:

rename table("my_table"), :old_name, to: :new_name

You get this:

** (FunctionClauseError) no function clause matching in Exandra.Connection.execute_ddl/1    
    
    The following arguments were given to Exandra.Connection.execute_ddl/1:
    
        # 1
        {:rename, %Ecto.Migration.Table{name: "cursors", prefix: nil, comment: nil, primary_key: true, engine: nil, options: nil}, :source_type, :resource_type}
    
    Attempted function clauses (showing 9 out of 9):
    
        def execute_ddl({command, %Ecto.Migration.Table{} = table, columns}) when command === :create or command === :create_if_not_exists
        def execute_ddl({:alter, %Ecto.Migration.Table{} = table, columns})
        def execute_ddl({command, %Ecto.Migration.Table{} = table, _}) when command === :drop or command === :drop_if_exists
        def execute_ddl({_command, %Ecto.Migration.Constraint{}, _})
        def execute_ddl({_command, %Ecto.Migration.Constraint{}})
        def execute_ddl({command, %Ecto.Migration.Index{} = index}) when command === :create or command === :create_if_not_exists
        def execute_ddl({command, %Ecto.Migration.Index{} = index, :restrict}) when command === :drop or command === :drop_if_exists
        def execute_ddl({command, %Ecto.Migration.Index{}, :cascade}) when command === :drop or command === :drop_if_exists
        def execute_ddl(string) when is_binary(string)
    
    (exandra 0.6.5) lib/exandra/connection.ex:645: Exandra.Connection.execute_ddl/1
    (ecto_sql 3.10.1) lib/ecto/adapters/sql.ex:1003: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:327: Ecto.Migration.Runner.log_and_execute_ddl/3
    (elixir 1.15.2) lib/enum.ex:1693: Enum."-map/2-lists^map/1-1-"/2
    (stdlib 5.0.2) timer.erl:270: :timer.tc/2
    (ecto_sql 3.10.1) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
    (ecto_sql 3.10.1) lib/ecto/migrator.ex:362: Ecto.Migrator.attempt/8
    (ecto_sql 3.10.1) lib/ecto/migrator.ex:283: anonymous fn/5 in Ecto.Migrator.do_up/5

Error casting '<< ... >>' to :binary_id

Steps to reproduce.
On the repo https://github.com/cyberchitta/M.ai perform

mix ecto.drop
mix ecto.create
mix ecto.migrate
mix run priv/repo/seeds.exs

results in the stacktrace

** (Ecto.ChangeError) value `<<96, 78, 199, 171, 247, 83, 76, 152, 146, 66, 173, 187, 123, 148, 19, 228>>` for `Mai.Chat.Message.chat_id` in `insert` does not match type :binary_id
    (ecto 3.11.2) lib/ecto/repo/schema.ex:1049: Ecto.Repo.Schema.dump_field!/6
    (ecto 3.11.2) lib/ecto/repo/schema.ex:1058: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5
    (stdlib 5.2) maps.erl:416: :maps.fold_1/4
    (ecto 3.11.2) lib/ecto/repo/schema.ex:1056: Ecto.Repo.Schema.dump_fields!/5
    (ecto 3.11.2) lib/ecto/repo/schema.ex:989: Ecto.Repo.Schema.dump_changes!/7
    (ecto 3.11.2) lib/ecto/repo/schema.ex:367: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
    (ecto 3.11.2) lib/ecto/repo/schema.ex:273: Ecto.Repo.Schema.insert!/4
    (elixir 1.16.2) lib/enum.ex:992: anonymous fn/3 in Enum.each/2
    (elixir 1.16.2) lib/enum.ex:4388: Enum.reduce_range/5
    (elixir 1.16.2) lib/enum.ex:2532: Enum.each/2
    (elixir 1.16.2) lib/enum.ex:992: anonymous fn/3 in Enum.each/2
    (elixir 1.16.2) lib/enum.ex:4388: Enum.reduce_range/5
    (elixir 1.16.2) lib/enum.ex:2532: Enum.each/2
    priv/repo/seeds.exs:22: (file)

However, <<96, 78, 199, 171, 247, 83, 76, 152, 146, 66, 173, 187, 123, 148, 19, 228>> is a 16 byte binary, so it should be a uuid i.e. a :binary_id, and the cast should work.
In fact, a very similar insert earlier in the same script (for inserting a new chat with a foreign key) does actually work.
UPDATE. Using exandra 0.10.2

Multiple keyspaces support

Hey! I just discovered Exandra while randomly looking to xandra dependents on Hex and it seems it would simplify a lot some codebases we're working on, but that would require support for querying across multiple keyspaces.

Right now, I see it's mainly meant to be used with a single keyspace (since a keyspace is required to be passed in start_link), but I already verified that it's possible to query tables on other keyspaces by just using

from "<keyspace>.<table>"

Would it be possible to map the different keyspaces onto Ecto prefixes? From the documentation it seems that MySQL maps them on different databases, which are more or less the equivalents of keyspaces. From the tests it seems to be supported at least in migrations, but passing prefix: :foo in Repo.all doesn't seem to work (though it sets the prefix on the returned schema).

If you think this is possible and it would be a desirable feature to have, I can try to tackle this with a PR.

Cannot specify Xandra query options

Describe the bug
Xandra query options (eg :uuid_format) no longer work, crashing with ** (NimbleOptions.ValidationError) unknown options [:uuid_format], valid options are: [:compressor, :force, :tracing, :custom_payload, :telemetry_metadata, :timeout].

I believe this is because the same options are passed to Xandra.prepare and Xandra.execute, and with whatyouhide/xandra@f9c34be Xandra.prepare does no longer validate valid prepare options only.

To Reproduce
Steps to reproduce the behavior:

  1. Perform a query with any custom option from Xandra.execute
  2. The error gets thrown

Expected behavior
Valid options are passed to Xandra.execute

Desktop (please complete the following information):

  • OS: NixOS 24.05 (Uakari)
  • Elixir: 1.16.0-OTP25
  • exandra: 0.10.1
  • xandra: 0.18.1

Error creating table `Missing ')'`

Discussed in #53

Originally posted by restlessronin March 28, 2024
I am successfully running migrations now. One of my migrations is giving me the following

11:32:40.004 [info] create table messages
** (Xandra.Error) line 1:32 : Missing ')'
    (ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1161: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.11.1) lib/ecto/migration/runner.ex:348: Ecto.Migration.Runner.log_and_execute_ddl/3
    (elixir 1.16.2) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (stdlib 5.2) timer.erl:270: :timer.tc/2
    (ecto_sql 3.11.1) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
    (ecto_sql 3.11.1) lib/ecto/migrator.ex:365: Ecto.Migrator.attempt/8

Here is the migration being attempted

defmodule Mai.Repo.Migrations.CreateMessages do
  use Ecto.Migration

  def change do
    create table(:messages, primary_key: false) do
      add(:id, :binary_id, primary_key: true)
      add(:order, :int)
      add(:role, :string)
      add(:content, :string)

      add(:chat_id, :binary_id)
      add(:original_message_id, :binary_id)

      timestamps()
    end
  end
end

i changed from :integer to :int, but that didn't seem to matter.

UPDATE. When I remove the :order field, however, the migration succeeds.


UPDATE. Using exandra 0.10.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.