-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace clickhouse implementation with a driver
- Loading branch information
Showing
18 changed files
with
143 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClickHouse | ||
class Click < Base | ||
class Click < ClickHouseRecord | ||
self.table_name = 'clicks' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClickHouse | ||
class ClickHouseRecord < ApplicationRecord | ||
self.abstract_class = true | ||
|
||
connects_to database: { writing: :clickhouse, reading: :clickhouse } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClickHouse | ||
class PageView < Base | ||
class PageView < ClickHouseRecord | ||
self.table_name = 'page_views' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module ClickHouse | ||
class Session < Base | ||
class Session < ClickHouseRecord | ||
self.table_name = 'sessions' | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,39 @@ | ||
# PostgreSQL. Versions 9.3 and up are supported. | ||
# | ||
# Install the pg driver: | ||
# gem install pg | ||
# On macOS with Homebrew: | ||
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config | ||
# On Windows: | ||
# gem install pg | ||
# Choose the win32 build. | ||
# Install PostgreSQL and put its /bin directory on your path. | ||
# | ||
# Configure Using Gemfile | ||
# gem "pg" | ||
# | ||
default: &default | ||
default_primary: &default_primary | ||
adapter: postgresql | ||
encoding: unicode | ||
# For details on connection pooling, see Rails configuration guide | ||
# https://guides.rubyonrails.org/configuring.html#database-pooling | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
|
||
development: | ||
<<: *default | ||
database: sql_book_development | ||
|
||
# The specified database role being used to connect to PostgreSQL. | ||
# To create additional roles in PostgreSQL see `$ createuser --help`. | ||
# When left blank, PostgreSQL will use the default role. This is | ||
# the same name as the operating system user running Rails. | ||
#username: sql_book | ||
|
||
# The password associated with the PostgreSQL role (username). | ||
#password: | ||
|
||
# Connect on a TCP socket. Omitted by default since the client uses a | ||
# domain socket that doesn't need configuration. Windows does not have | ||
# domain sockets, so uncomment these lines. | ||
#host: localhost | ||
|
||
# The TCP port the server listens on. Defaults to 5432. | ||
# If your server runs on a different port number, change accordingly. | ||
#port: 5432 | ||
|
||
# Schema search path. The server defaults to $user,public | ||
#schema_search_path: myapp,sharedapp,public | ||
default_clickhouse: &default_clickhouse | ||
adapter: clickhouse | ||
encoding: unicode | ||
username: sql_book | ||
migrations_paths: db/migrate_clickhouse | ||
|
||
# Minimum log levels, in increasing order: | ||
# debug5, debug4, debug3, debug2, debug1, | ||
# log, notice, warning, error, fatal, and panic | ||
# Defaults to warning. | ||
#min_messages: notice | ||
development: | ||
primary: | ||
<<: *default_primary | ||
database: sql_book_development | ||
clickhouse: | ||
<<: *default_clickhouse | ||
database: sql_book_development | ||
password: password | ||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
<<: *default | ||
database: sql_book_test | ||
primary: | ||
<<: *default_primary | ||
database: sql_book_test | ||
clickhouse: | ||
<<: *default_clickhouse | ||
database: sql_book_test | ||
password: password | ||
|
||
# As with config/credentials.yml, you never want to store sensitive information, | ||
# like your database password, in your source code. If your source code is | ||
# ever seen by anyone, they now have access to your database. | ||
# | ||
# Instead, provide the password or a full connection URL as an environment | ||
# variable when you boot the app. For example: | ||
# | ||
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" | ||
# | ||
# If the connection URL is provided in the special DATABASE_URL environment | ||
# variable, Rails will automatically merge its configuration values on top of | ||
# the values provided in this file. Alternatively, you can specify a connection | ||
# URL environment variable explicitly: | ||
# | ||
# production: | ||
# url: <%= ENV["MY_APP_DATABASE_URL"] %> | ||
# | ||
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database | ||
# for a full overview on how database connection configuration can be specified. | ||
# | ||
production: | ||
<<: *default | ||
database: sql_book_production | ||
username: sql_book | ||
password: <%= ENV["SQL_BOOK_DATABASE_PASSWORD"] %> | ||
primary: | ||
<<: *default_primary | ||
database: sql_book_production | ||
username: sql_book | ||
password: <%= ENV["SQL_BOOK_DATABASE_PASSWORD"] %> | ||
clickhouse: | ||
<<: *default_clickhouse | ||
database: sql_book_production | ||
password: <%= ENV["SQL_BOOK_CLICKHOUSE_DATABASE_PASSWORD"] %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# This file is the source Rails uses to define your schema when running `rails | ||
# clickhouse:schema:load`. When creating a new database, `rails clickhouse:schema:load` tends to | ||
# be faster and is potentially less error prone than running all of your | ||
# migrations from scratch. Old migrations may fail to apply correctly if those | ||
# migrations use external dependencies or application code. | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ClickhouseActiverecord::Schema.define(version: 2024_01_05_210103) do | ||
|
||
# TABLE: clicks | ||
# SQL: CREATE TABLE sql_book_development.clicks ( `uuid` UUID, `data_source_uuid` UUID, `session_uuid` UUID, `visitor_uuid` UUID, `timestamp` Int64, `coordinates_x` UInt32, `coordinates_y` UInt32, `xpath` String, `inner_text` Nullable(String), `attribute_id` Nullable(String), `attribute_class` Nullable(String) ) ENGINE = MergeTree ORDER BY (data_source_uuid, toDate(timestamp)) SETTINGS index_granularity = 8192 | ||
# Could not dump table "clicks" because of following StandardError | ||
# Unknown type 'UUID' for column 'uuid' | ||
|
||
# TABLE: page_views | ||
# SQL: CREATE TABLE sql_book_development.page_views ( `uuid` UUID, `data_source_uuid` UUID, `session_uuid` UUID, `visitor_uuid` UUID, `timestamp` Int64, `url` String ) ENGINE = MergeTree ORDER BY (data_source_uuid, toDate(timestamp)) SETTINGS index_granularity = 8192 | ||
# Could not dump table "page_views" because of following StandardError | ||
# Unknown type 'UUID' for column 'uuid' | ||
|
||
# TABLE: sessions | ||
# SQL: CREATE TABLE sql_book_development.sessions ( `uuid` UUID, `data_source_uuid` UUID, `session_uuid` UUID, `visitor_uuid` UUID, `timestamp` Int64, `viewport_x` UInt32, `viewport_y` UInt32, `device_x` UInt32, `device_y` UInt32, `referrer` Nullable(String), `locale` Nullable(String), `useragent` Nullable(String), `browser` Nullable(String), `device_type` Nullable(String), `timezone` Nullable(String), `country_code` Nullable(String), `utm_source` Nullable(String), `utm_medium` Nullable(String), `utm_campaign` Nullable(String), `utm_content` Nullable(String), `utm_term` Nullable(String) ) ENGINE = MergeTree ORDER BY (data_source_uuid, toDate(timestamp)) SETTINGS index_granularity = 8192 | ||
# Could not dump table "sessions" because of following StandardError | ||
# Unknown type 'UUID' for column 'uuid' | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateClick < ActiveRecord::Migration[7.1] | ||
def change # rubocop:disable Metrics/MethodLength | ||
create_table :clicks, id: false, options: 'MergeTree ORDER BY (data_source_uuid, toDate(timestamp))' do |t| | ||
t.uuid :uuid, null: false | ||
t.uuid :data_source_uuid, null: false | ||
t.uuid :session_uuid, null: false | ||
t.uuid :visitor_uuid, null: false | ||
t.bigint :timestamp, null: false | ||
t.integer :coordinates_x, null: false | ||
t.integer :coordinates_y, null: false | ||
t.string :xpath, null: false | ||
t.string :inner_text, null: true | ||
t.string :attribute_id, null: true | ||
t.string :attribute_class, null: true | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class PageView < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :page_views, id: false, options: 'MergeTree ORDER BY (data_source_uuid, toDate(timestamp))' do |t| | ||
t.uuid :uuid, null: false | ||
t.uuid :data_source_uuid, null: false | ||
t.uuid :session_uuid, null: false | ||
t.uuid :visitor_uuid, null: false | ||
t.bigint :timestamp, null: false | ||
t.string :url, null: false | ||
end | ||
end | ||
end |
Oops, something went wrong.