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

Don't throw exception when creating database #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

PoroshkinaVV
Copy link

This PR aims to fix exception when creating database.

bundle exec rake db:create
Response code: 200:
clickhouse-5.my-cluster.cloud.b-pl.pro 9000 82 Code: 82. DB::Exception: Database my_database already exists. (DATABASE_ALREADY_EXISTS) (version 23.8.3.48 (official build)) 
Code: 82. DB::Exception: There was an error on [clickhouse-5.my-cluster.cloud.b-pl.pro:9000]: Code: 82. DB::Exception: Database my_database already exists. (DATABASE_ALREADY_EXISTS) (version 23.8.3.48 (official build)). (DATABASE_ALREADY_EXISTS) (version 23.8.3.48 (official build))
Couldn't create 'my_database' database. Please check your configuration.
rake aborted!

Clickhouse docs:

Clause IF NOT EXISTS
If the db_name database already exists, then ClickHouse does not create a new database and:

Doesn’t throw an exception if clause is specified.
Throws an exception if clause isn’t specified.

@PoroshkinaVV
Copy link
Author

@PNixx, what do you think?

@PNixx
Copy link
Owner

PNixx commented Mar 5, 2024

I will check

@PNixx
Copy link
Owner

PNixx commented Mar 11, 2024

% rake db:create:clickhouse
Database 'clickhouse_test' already exists

Correct behavior when creating a database. Write your version of Ruby, Rails and ClickHouse.

@PoroshkinaVV
Copy link
Author

Ruby: 3.2.0
Rails: 7.1.3
Clickhouse: 23.8.3.48

@PNixx
Copy link
Owner

PNixx commented Mar 12, 2024

gem version?

@PoroshkinaVV
Copy link
Author

latest: 1.0.4

@PoroshkinaVV
Copy link
Author

I also made this change based on method drop database. Not only because I have this error above.

It contains directive 'IF EXISTS', but create database for some reason doesn't have 'IF NOT EXISTS':

sql = apply_cluster "DROP DATABASE IF EXISTS #{quote_table_name(name)}"

@PNixx
Copy link
Owner

PNixx commented Jul 11, 2024

Sorry, I mistake. You set in database.yml cluster information?

  cluster_name: 'cluster_name' # optional for creating tables in cluster 
  replica_name: '{replica}' # replica macros name, optional for creating replicated tables

@PoroshkinaVV
Copy link
Author

@PNixx yes

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.

2 participants