Перевод проекта на единую SQLite БД, WAL и обновление README для Windows

This commit is contained in:
2026-03-03 23:53:22 +05:00
parent 906a6cb91f
commit 9bfc6e668f
11 changed files with 100 additions and 34 deletions

2
.env
View File

@@ -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

3
.gitignore vendored
View File

@@ -5,3 +5,6 @@ public/*
!public/500.html
node_modules/
db/*.sqlite
db/*.sqlite3
db/*.sqlite3-wal
db/*.sqlite3-shm

View File

@@ -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/)

View File

@@ -1,4 +1,4 @@
module ClashDeckGenerator
module ClashDeckGenerator2
module Relations
class Cards < DB::Relation
schema :cards, infer: true

View File

@@ -1,4 +1,4 @@
module ClashDeckGenerator
module ClashDeckGenerator2
module Repos
class CardsRepo < DB::Repo[:cards]
def meta_cards

View File

@@ -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

View File

@@ -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

14
config/db/structure.sql Normal file
View File

@@ -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');

View File

@@ -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

View File

@@ -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

Binary file not shown.