diff --git a/.env b/.env index a944ba8..9d10cd9 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ # This is checked into source control, so put sensitive values into `.env.local` -DATABASE_URL=sqlite: db/clash_deck_generator2.sqlite +DATABASE_URL=sqlite://db/db.sqlite3 diff --git a/.gitignore b/.gitignore index 6bf55af..4310dc8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ public/* !public/500.html node_modules/ db/*.sqlite +db/*.sqlite3 +db/*.sqlite3-wal +db/*.sqlite3-shm diff --git a/README.md b/README.md index 7da731c..1b42733 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,59 @@ # ClashDeckGenerator2 -🌸 Welcome to your Hanami app! +Приложение на Hanami 2.3 (Ruby 3.4, SQLite). -## Getting started +## Запуск на Windows (через winget) -- Set up the project with `bin/setup` -- Run the server with `bin/dev` -- View the app at [http://localhost:2300](http://localhost:2300) -- Run the tests with `bundle exec rake` +### 1) Установить зависимости -## Useful links +```bat +winget install -e --id RubyInstallerTeam.RubyWithDevKit.3.4 +winget install -e --id SQLite.SQLite +winget install -e --id Git.Git +``` + +После установки открой новый терминал (чтобы обновился `PATH`). + +### 2) Установить Ruby-зависимости проекта + +```bat +bundle install +``` + +### 3) Подготовить БД + +```bat +bundle exec hanami db prepare +``` + +Команда создаст/обновит: +- [`db/db.sqlite3`](db/db.sqlite3) +- [`db/db_test.sqlite3`](db/db_test.sqlite3) + +### 4) Запуск приложения + +```bat +bundle exec puma -C config/puma.rb config.ru +``` + +Открыть: [http://localhost:2300](http://localhost:2300) + +## Важно про SQLite для Hanami + +Для корректной работы нужны **две части**: + +1. Ruby-модуль [`gem "sqlite3"`](Gemfile:17) — используется приложением и адаптером БД. + Устанавливается через [`bundle install`](README.md:27). +2. CLI-утилита `sqlite3` (отдельный бинарник) — нужна командам Hanami, например [`hanami db prepare`](README.md:33). + Ставится через [`winget install -e --id SQLite.SQLite`](README.md:13). + +Если `bundle` или `hanami` не находятся в `cmd`, проверь Ruby в `PATH` или временно добавь: + +```bat +set "PATH=C:\Ruby34-x64\bin;%PATH%" +``` + +## Полезные ссылки - [Hanami](http://hanamirb.org) -- [Hanami guides](https://guides.hanamirb.org/) +- [Hanami Guides](https://guides.hanamirb.org/) diff --git a/app/relations/cards.rb b/app/relations/cards.rb index a3ade95..a5cbe99 100644 --- a/app/relations/cards.rb +++ b/app/relations/cards.rb @@ -1,4 +1,4 @@ -module ClashDeckGenerator +module ClashDeckGenerator2 module Relations class Cards < DB::Relation schema :cards, infer: true diff --git a/app/repos/cards_repo.rb b/app/repos/cards_repo.rb index 6e42ec5..e72372a 100644 --- a/app/repos/cards_repo.rb +++ b/app/repos/cards_repo.rb @@ -1,4 +1,4 @@ -module ClashDeckGenerator +module ClashDeckGenerator2 module Repos class CardsRepo < DB::Repo[:cards] def meta_cards diff --git a/config/db/migrate/20260303180000_create_cards.rb b/config/db/migrate/20260303180000_create_cards.rb new file mode 100644 index 0000000..7c7077c --- /dev/null +++ b/config/db/migrate/20260303180000_create_cards.rb @@ -0,0 +1,16 @@ +Sequel.migration do + change do + create_table :cards do + primary_key :id + + column :name, String, null: false + column :elixir_cost, Integer, null: false + column :rarity, String + column :type, String + column :is_meta, Integer, default: 0 + + column :created_at, DateTime, null: false, default: Sequel::CURRENT_TIMESTAMP + column :updated_at, DateTime, null: false, default: Sequel::CURRENT_TIMESTAMP + end + end +end diff --git a/config/db/migrate/20260303200000_enable_sqlite_wal.rb b/config/db/migrate/20260303200000_enable_sqlite_wal.rb new file mode 100644 index 0000000..115f0e6 --- /dev/null +++ b/config/db/migrate/20260303200000_enable_sqlite_wal.rb @@ -0,0 +1,11 @@ +Sequel.migration do + up do + run "PRAGMA journal_mode = WAL;" + run "PRAGMA synchronous = NORMAL;" + end + + down do + run "PRAGMA journal_mode = DELETE;" + run "PRAGMA synchronous = FULL;" + end +end diff --git a/config/db/structure.sql b/config/db/structure.sql new file mode 100644 index 0000000..4bd5d22 --- /dev/null +++ b/config/db/structure.sql @@ -0,0 +1,14 @@ +CREATE TABLE `schema_migrations`(`filename` varchar(255) NOT NULL PRIMARY KEY); +CREATE TABLE `cards`( + `id` integer NOT NULL PRIMARY KEY AUTOINCREMENT, + `name` varchar(255) NOT NULL, + `elixir_cost` integer NOT NULL, + `rarity` varchar(255), + `type` varchar(255), + `is_meta` integer DEFAULT(0), + `created_at` timestamp DEFAULT(datetime(CURRENT_TIMESTAMP, 'localtime')) NOT NULL, + `updated_at` timestamp DEFAULT(datetime(CURRENT_TIMESTAMP, 'localtime')) NOT NULL +); +INSERT INTO schema_migrations (filename) VALUES +('20260303180000_create_cards.rb'), +('20260303200000_enable_sqlite_wal.rb'); diff --git a/config/providers/db.rb b/config/providers/db.rb deleted file mode 100644 index c79b331..0000000 --- a/config/providers/db.rb +++ /dev/null @@ -1,20 +0,0 @@ -warn "DB PROVIDER FILE LOADED" - -ClashDeckGenerator2::App.register_provider :db do -warn "DB PROVIDER REGISTERED" - prepare do - warn "DB PROVIDER PREPARE" - require "hanami/db" - end - - start do - warn "DB PROVIDER START" - config = target["settings"].database_url - - db = Hanami::DB.new(config) - - register "db", db - register "db.rom", db.rom - register "db.gateway", db.gateway - end -end \ No newline at end of file diff --git a/config/settings.rb b/config/settings.rb index 01a69e3..d18a61f 100644 --- a/config/settings.rb +++ b/config/settings.rb @@ -2,8 +2,6 @@ module ClashDeckGenerator2 class Settings < Hanami::Settings - # Define your app settings here, for example: - # - # setting :my_flag, default: false, constructor: Types::Params::Bool + setting :database_url, constructor: Types::String end end diff --git a/db/development.sqlite3 b/db/development.sqlite3 deleted file mode 100644 index f48fa96..0000000 Binary files a/db/development.sqlite3 and /dev/null differ