rubydb 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +20 -0
- data/.github/ISSUE_TEMPLATE/bug.yml +0 -0
- data/.github/ISSUE_TEMPLATE/feature.yml +0 -0
- data/.github/ISSUE_TEMPLATE/performance.yml +0 -0
- data/.github/ISSUE_TEMPLATE/security.yml +0 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +15 -0
- data/.github/dependabot.yml +0 -0
- data/.github/workflows/benchmark.yml +26 -0
- data/.github/workflows/compatibility.yml +63 -0
- data/.github/workflows/fuzz.yml +33 -0
- data/.github/workflows/lint.yml +21 -0
- data/.github/workflows/operations.yml +24 -0
- data/.github/workflows/production-validation.yml +111 -0
- data/.github/workflows/release.yml +77 -0
- data/.github/workflows/security.yml +37 -0
- data/.github/workflows/test.yml +26 -0
- data/.github/workflows/workload.yml +58 -0
- data/.gitignore +43 -0
- data/.rspec +4 -0
- data/.rubocop.yml +44 -0
- data/.ruby-version +1 -0
- data/.standard.yml +14 -0
- data/ARCHITECTURE.md +21 -0
- data/CHANGELOG.md +31 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/CONTRIBUTING.md +29 -0
- data/GOVERNANCE.md +16 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +71 -0
- data/LICENSE +60 -0
- data/README.md +162 -0
- data/ROADMAP.md +27 -0
- data/Rakefile +71 -0
- data/SECURITY.md +54 -0
- data/SUPPORT.md +14 -0
- data/adapters/activerecord/Gemfile +11 -0
- data/adapters/activerecord/README.md +9 -0
- data/adapters/activerecord/lib/active_record/connection_adapters/rubydb_adapter.rb +887 -0
- data/adapters/activerecord/rubydb-activerecord.gemspec +27 -0
- data/adapters/activerecord/spec/rubydb_adapter_integration_spec.rb +151 -0
- data/adapters/ruby/README.md +18 -0
- data/adapters/sequel/README.md +11 -0
- data/bin/rubydb +19 -0
- data/bin/rubydb-server +126 -0
- data/config/development.yml +0 -0
- data/config/monitoring/prometheus-alerts.yml +39 -0
- data/config/production.yml +36 -0
- data/config/test.yml +0 -0
- data/docs/README.md +71 -0
- data/docs/architecture/concurrency.md +14 -0
- data/docs/architecture/current-state.md +125 -0
- data/docs/architecture/execution-engine.md +25 -0
- data/docs/architecture/indexes.md +19 -0
- data/docs/architecture/mvcc.md +19 -0
- data/docs/architecture/overview.md +13 -0
- data/docs/architecture/pages.md +11 -0
- data/docs/architecture/production-roadmap.md +82 -0
- data/docs/architecture/query-planner.md +20 -0
- data/docs/architecture/recovery.md +18 -0
- data/docs/architecture/sql-engine.md +12 -0
- data/docs/architecture/storage-engine.md +14 -0
- data/docs/architecture/transactions.md +10 -0
- data/docs/architecture/wal.md +28 -0
- data/docs/cli-cheatsheet.md +98 -0
- data/docs/cli.md +275 -0
- data/docs/contributing/architecture.md +9 -0
- data/docs/contributing/benchmarking.md +14 -0
- data/docs/contributing/development.md +16 -0
- data/docs/contributing/release-process.md +49 -0
- data/docs/contributing/testing.md +16 -0
- data/docs/debugging.md +229 -0
- data/docs/developer/branching.md +10 -0
- data/docs/developer/database-diff.md +10 -0
- data/docs/developer/local-development.md +17 -0
- data/docs/developer/snapshots.md +9 -0
- data/docs/developer/temporal-data.md +10 -0
- data/docs/developer-guide.md +297 -0
- data/docs/getting-started/first-database.md +16 -0
- data/docs/getting-started/first-query.md +13 -0
- data/docs/getting-started/installation.md +19 -0
- data/docs/getting-started/local-to-production.md +300 -0
- data/docs/getting-started/quickstart.md +17 -0
- data/docs/getting-started/rails.md +16 -0
- data/docs/hardening_backlog.md +93 -0
- data/docs/lessons-learned.md +112 -0
- data/docs/operations/backups.md +33 -0
- data/docs/operations/disaster-recovery.md +31 -0
- data/docs/operations/failover.md +30 -0
- data/docs/operations/monitoring.md +25 -0
- data/docs/operations/production-guide.md +295 -0
- data/docs/operations/production-runbook.md +45 -0
- data/docs/operations/replication.md +33 -0
- data/docs/operations/restore.md +6 -0
- data/docs/operations/runbook.md +34 -0
- data/docs/operations/upgrades.md +14 -0
- data/docs/operations/workload-testing.md +17 -0
- data/docs/production-readiness.md +118 -0
- data/docs/production_validation.md +150 -0
- data/docs/rails/active-record.md +11 -0
- data/docs/rails/compatibility-guide.md +90 -0
- data/docs/rails/database-yml.md +92 -0
- data/docs/rails/installation.md +17 -0
- data/docs/rails/migrations.md +17 -0
- data/docs/rails/production.md +82 -0
- data/docs/rails/troubleshooting.md +18 -0
- data/docs/release.md +59 -0
- data/docs/server/architecture.md +10 -0
- data/docs/server/authentication.md +10 -0
- data/docs/server/configuration.md +16 -0
- data/docs/server/connection-pooling.md +10 -0
- data/docs/server/deployment.md +10 -0
- data/docs/server/protocol.md +12 -0
- data/docs/sql/compatibility-guide.md +82 -0
- data/docs/sql/compatibility.md +39 -0
- data/docs/sql/data-types.md +10 -0
- data/docs/sql/functions.md +9 -0
- data/docs/sql/joins.md +9 -0
- data/docs/sql/operators.md +9 -0
- data/docs/sql/sqlite-compatibility.md +21 -0
- data/docs/sql/syntax.md +10 -0
- data/docs/sql/transactions.md +10 -0
- data/docs/troubleshooting.md +244 -0
- data/exe/rubydb +23 -0
- data/lib/rubydb/backup/archive.rb +334 -0
- data/lib/rubydb/backup/backup.rb +401 -0
- data/lib/rubydb/backup/incremental.rb +353 -0
- data/lib/rubydb/backup/restore.rb +290 -0
- data/lib/rubydb/backup/snapshot.rb +267 -0
- data/lib/rubydb/backup/verification.rb +279 -0
- data/lib/rubydb/branching/branch.rb +181 -0
- data/lib/rubydb/branching/branch_manager.rb +311 -0
- data/lib/rubydb/branching/branch_metadata.rb +140 -0
- data/lib/rubydb/branching/checkout.rb +166 -0
- data/lib/rubydb/branching/copy_on_write.rb +272 -0
- data/lib/rubydb/branching/diff.rb +138 -0
- data/lib/rubydb/branching/merge.rb +285 -0
- data/lib/rubydb/build_info.rb +15 -0
- data/lib/rubydb/catalog/catalog.rb +391 -0
- data/lib/rubydb/catalog/column.rb +112 -0
- data/lib/rubydb/catalog/constraint.rb +180 -0
- data/lib/rubydb/catalog/database.rb +184 -0
- data/lib/rubydb/catalog/index.rb +97 -0
- data/lib/rubydb/catalog/schema.rb +103 -0
- data/lib/rubydb/catalog/sequence.rb +90 -0
- data/lib/rubydb/catalog/system_catalog.rb +698 -0
- data/lib/rubydb/catalog/table.rb +178 -0
- data/lib/rubydb/catalog/trigger.rb +102 -0
- data/lib/rubydb/catalog/view.rb +66 -0
- data/lib/rubydb/cli/application.rb +163 -0
- data/lib/rubydb/cli/commands/backup.rb +81 -0
- data/lib/rubydb/cli/commands/branch.rb +72 -0
- data/lib/rubydb/cli/commands/checkout.rb +54 -0
- data/lib/rubydb/cli/commands/create.rb +58 -0
- data/lib/rubydb/cli/commands/diff.rb +77 -0
- data/lib/rubydb/cli/commands/doctor.rb +74 -0
- data/lib/rubydb/cli/commands/drop.rb +57 -0
- data/lib/rubydb/cli/commands/init.rb +102 -0
- data/lib/rubydb/cli/commands/inspect.rb +95 -0
- data/lib/rubydb/cli/commands/merge.rb +63 -0
- data/lib/rubydb/cli/commands/migrate.rb +62 -0
- data/lib/rubydb/cli/commands/restart.rb +39 -0
- data/lib/rubydb/cli/commands/restore.rb +121 -0
- data/lib/rubydb/cli/commands/shell.rb +365 -0
- data/lib/rubydb/cli/commands/snapshot.rb +79 -0
- data/lib/rubydb/cli/commands/start.rb +82 -0
- data/lib/rubydb/cli/commands/status.rb +92 -0
- data/lib/rubydb/cli/commands/stop.rb +47 -0
- data/lib/rubydb/cli/commands/vacuum.rb +58 -0
- data/lib/rubydb/cli/formatter.rb +221 -0
- data/lib/rubydb/cli/output.rb +168 -0
- data/lib/rubydb/client/client.rb +304 -0
- data/lib/rubydb/client/connection.rb +415 -0
- data/lib/rubydb/client/connection_pool.rb +168 -0
- data/lib/rubydb/client/connection_url.rb +96 -0
- data/lib/rubydb/client/prepared_statement.rb +60 -0
- data/lib/rubydb/client/result.rb +123 -0
- data/lib/rubydb/client/statement.rb +52 -0
- data/lib/rubydb/client/transaction.rb +130 -0
- data/lib/rubydb/concurrency/concurrency.rb +19 -0
- data/lib/rubydb/concurrency/deadlock_detector.rb +150 -0
- data/lib/rubydb/concurrency/latch.rb +101 -0
- data/lib/rubydb/concurrency/lock_graph.rb +165 -0
- data/lib/rubydb/concurrency/mutex.rb +183 -0
- data/lib/rubydb/concurrency/rw_lock.rb +180 -0
- data/lib/rubydb/concurrency/scheduler.rb +250 -0
- data/lib/rubydb/concurrency/worker_pool.rb +143 -0
- data/lib/rubydb/configuration/config.rb +170 -0
- data/lib/rubydb/configuration/defaults.rb +179 -0
- data/lib/rubydb/configuration/environment.rb +152 -0
- data/lib/rubydb/configuration/parser.rb +185 -0
- data/lib/rubydb/configuration/validation.rb +221 -0
- data/lib/rubydb/constants.rb +74 -0
- data/lib/rubydb/constraints/check.rb +181 -0
- data/lib/rubydb/constraints/constraint.rb +101 -0
- data/lib/rubydb/constraints/foreign_key.rb +130 -0
- data/lib/rubydb/constraints/not_null.rb +64 -0
- data/lib/rubydb/constraints/primary_key.rb +99 -0
- data/lib/rubydb/constraints/unique.rb +108 -0
- data/lib/rubydb/constraints/validator.rb +350 -0
- data/lib/rubydb/errors/authentication_error.rb +10 -0
- data/lib/rubydb/errors/authorization_error.rb +23 -0
- data/lib/rubydb/errors/client_error.rb +10 -0
- data/lib/rubydb/errors/configuration_error.rb +10 -0
- data/lib/rubydb/errors/connection_error.rb +10 -0
- data/lib/rubydb/errors/constraint_error.rb +23 -0
- data/lib/rubydb/errors/corruption_error.rb +10 -0
- data/lib/rubydb/errors/database_error.rb +10 -0
- data/lib/rubydb/errors/error.rb +20 -0
- data/lib/rubydb/errors/execution_error.rb +10 -0
- data/lib/rubydb/errors/parser_error.rb +10 -0
- data/lib/rubydb/errors/recovery_error.rb +10 -0
- data/lib/rubydb/errors/replication_error.rb +10 -0
- data/lib/rubydb/errors/server_error.rb +6 -0
- data/lib/rubydb/errors/storage_error.rb +10 -0
- data/lib/rubydb/errors/transaction_error.rb +10 -0
- data/lib/rubydb/execution/aggregate_executor.rb +138 -0
- data/lib/rubydb/execution/delete_executor.rb +112 -0
- data/lib/rubydb/execution/distinct_executor.rb +135 -0
- data/lib/rubydb/execution/executor.rb +1192 -0
- data/lib/rubydb/execution/expression.rb +193 -0
- data/lib/rubydb/execution/index_scan.rb +142 -0
- data/lib/rubydb/execution/insert_executor.rb +217 -0
- data/lib/rubydb/execution/join_executor.rb +249 -0
- data/lib/rubydb/execution/limit_executor.rb +85 -0
- data/lib/rubydb/execution/optimizer.rb +215 -0
- data/lib/rubydb/execution/plan.rb +361 -0
- data/lib/rubydb/execution/planner.rb +546 -0
- data/lib/rubydb/execution/predicate.rb +235 -0
- data/lib/rubydb/execution/scan.rb +49 -0
- data/lib/rubydb/execution/sequential_scan.rb +63 -0
- data/lib/rubydb/execution/sort_executor.rb +185 -0
- data/lib/rubydb/execution/update_executor.rb +162 -0
- data/lib/rubydb/functions/aggregate.rb +70 -0
- data/lib/rubydb/functions/date_functions.rb +278 -0
- data/lib/rubydb/functions/function.rb +85 -0
- data/lib/rubydb/functions/json_functions.rb +215 -0
- data/lib/rubydb/functions/numeric_functions.rb +346 -0
- data/lib/rubydb/functions/scalar.rb +52 -0
- data/lib/rubydb/functions/string_functions.rb +383 -0
- data/lib/rubydb/functions/system_functions.rb +246 -0
- data/lib/rubydb/history/as_of.rb +238 -0
- data/lib/rubydb/history/change.rb +105 -0
- data/lib/rubydb/history/history.rb +131 -0
- data/lib/rubydb/history/history_manager.rb +229 -0
- data/lib/rubydb/history/temporal_query.rb +202 -0
- data/lib/rubydb/history/timeline.rb +144 -0
- data/lib/rubydb/indexes/btree.rb +186 -0
- data/lib/rubydb/indexes/btree_cursor.rb +258 -0
- data/lib/rubydb/indexes/btree_node.rb +385 -0
- data/lib/rubydb/indexes/hash_index.rb +150 -0
- data/lib/rubydb/indexes/index.rb +71 -0
- data/lib/rubydb/indexes/index_manager.rb +406 -0
- data/lib/rubydb/indexes/index_scan.rb +470 -0
- data/lib/rubydb/migrations/migration.rb +254 -0
- data/lib/rubydb/migrations/migration_lock.rb +146 -0
- data/lib/rubydb/migrations/migration_manager.rb +176 -0
- data/lib/rubydb/migrations/migration_version.rb +71 -0
- data/lib/rubydb/migrations/schema_diff.rb +211 -0
- data/lib/rubydb/migrations/schema_version.rb +64 -0
- data/lib/rubydb/monitoring/events.rb +160 -0
- data/lib/rubydb/monitoring/health.rb +222 -0
- data/lib/rubydb/monitoring/logger.rb +193 -0
- data/lib/rubydb/monitoring/metrics.rb +359 -0
- data/lib/rubydb/monitoring/performance.rb +176 -0
- data/lib/rubydb/monitoring/statistics.rb +170 -0
- data/lib/rubydb/mvcc/garbage_collector.rb +199 -0
- data/lib/rubydb/mvcc/mvcc.rb +16 -0
- data/lib/rubydb/mvcc/snapshot.rb +147 -0
- data/lib/rubydb/mvcc/vacuum.rb +180 -0
- data/lib/rubydb/mvcc/version.rb +106 -0
- data/lib/rubydb/mvcc/version_store.rb +398 -0
- data/lib/rubydb/mvcc/visibility.rb +109 -0
- data/lib/rubydb/protocol/capabilities.rb +125 -0
- data/lib/rubydb/protocol/decoder.rb +145 -0
- data/lib/rubydb/protocol/encoder.rb +136 -0
- data/lib/rubydb/protocol/handshake.rb +305 -0
- data/lib/rubydb/protocol/message.rb +121 -0
- data/lib/rubydb/protocol/protocol.rb +277 -0
- data/lib/rubydb/protocol/version.rb +54 -0
- data/lib/rubydb/rails/adapter.rb +239 -0
- data/lib/rubydb/rails/connection.rb +314 -0
- data/lib/rubydb/rails/database_statements.rb +122 -0
- data/lib/rubydb/rails/migration.rb +131 -0
- data/lib/rubydb/rails/quoting.rb +109 -0
- data/lib/rubydb/rails/result.rb +120 -0
- data/lib/rubydb/rails/schema_statements.rb +339 -0
- data/lib/rubydb/rails/transaction.rb +105 -0
- data/lib/rubydb/rails/type.rb +126 -0
- data/lib/rubydb/recovery/checkpoint.rb +257 -0
- data/lib/rubydb/recovery/consistency.rb +467 -0
- data/lib/rubydb/recovery/corruption_detector.rb +5 -0
- data/lib/rubydb/recovery/crash_recovery.rb +387 -0
- data/lib/rubydb/recovery/recovery_manager.rb +206 -0
- data/lib/rubydb/recovery/redo.rb +237 -0
- data/lib/rubydb/recovery/undo.rb +206 -0
- data/lib/rubydb/replication/failover.rb +5 -0
- data/lib/rubydb/replication/fencing.rb +63 -0
- data/lib/rubydb/replication/primary.rb +450 -0
- data/lib/rubydb/replication/replica.rb +384 -0
- data/lib/rubydb/replication/replication_log.rb +200 -0
- data/lib/rubydb/replication/replication_manager.rb +308 -0
- data/lib/rubydb/replication/replication_slot.rb +295 -0
- data/lib/rubydb/replication/replication_stream.rb +201 -0
- data/lib/rubydb/rubydb.rb +560 -0
- data/lib/rubydb/security/access_control.rb +254 -0
- data/lib/rubydb/security/audit_log.rb +213 -0
- data/lib/rubydb/security/authentication.rb +302 -0
- data/lib/rubydb/security/authorization.rb +282 -0
- data/lib/rubydb/security/credentials.rb +196 -0
- data/lib/rubydb/security/password.rb +215 -0
- data/lib/rubydb/security/permissions.rb +74 -0
- data/lib/rubydb/security/role.rb +101 -0
- data/lib/rubydb/security/user.rb +86 -0
- data/lib/rubydb/server/connection.rb +366 -0
- data/lib/rubydb/server/connection_pool.rb +193 -0
- data/lib/rubydb/server/lifecycle.rb +228 -0
- data/lib/rubydb/server/listener.rb +136 -0
- data/lib/rubydb/server/request_handler.rb +276 -0
- data/lib/rubydb/server/server.rb +364 -0
- data/lib/rubydb/server/session.rb +369 -0
- data/lib/rubydb/server/worker.rb +210 -0
- data/lib/rubydb/server/worker_pool.rb +168 -0
- data/lib/rubydb/sql/ast/alter_table.rb +169 -0
- data/lib/rubydb/sql/ast/begin_transaction.rb +47 -0
- data/lib/rubydb/sql/ast/commit.rb +37 -0
- data/lib/rubydb/sql/ast/constraint.rb +83 -0
- data/lib/rubydb/sql/ast/create_database.rb +41 -0
- data/lib/rubydb/sql/ast/create_index.rb +61 -0
- data/lib/rubydb/sql/ast/create_schema.rb +52 -0
- data/lib/rubydb/sql/ast/create_table.rb +187 -0
- data/lib/rubydb/sql/ast/delete.rb +54 -0
- data/lib/rubydb/sql/ast/drop_database.rb +41 -0
- data/lib/rubydb/sql/ast/drop_index.rb +41 -0
- data/lib/rubydb/sql/ast/drop_schema.rb +49 -0
- data/lib/rubydb/sql/ast/drop_table.rb +49 -0
- data/lib/rubydb/sql/ast/explain.rb +64 -0
- data/lib/rubydb/sql/ast/expression.rb +604 -0
- data/lib/rubydb/sql/ast/insert.rb +82 -0
- data/lib/rubydb/sql/ast/node.rb +42 -0
- data/lib/rubydb/sql/ast/rollback.rb +63 -0
- data/lib/rubydb/sql/ast/savepoint.rb +59 -0
- data/lib/rubydb/sql/ast/select.rb +88 -0
- data/lib/rubydb/sql/ast/set_operation.rb +20 -0
- data/lib/rubydb/sql/ast/trigger.rb +29 -0
- data/lib/rubydb/sql/ast/update.rb +88 -0
- data/lib/rubydb/sql/ast/vacuum.rb +19 -0
- data/lib/rubydb/sql/ast/view.rb +32 -0
- data/lib/rubydb/sql/ast/with.rb +32 -0
- data/lib/rubydb/sql/grammar.rb +86 -0
- data/lib/rubydb/sql/keywords.rb +156 -0
- data/lib/rubydb/sql/lexer.rb +214 -0
- data/lib/rubydb/sql/operators.rb +100 -0
- data/lib/rubydb/sql/parser.rb +1185 -0
- data/lib/rubydb/sql/planner/analyzer.rb +302 -0
- data/lib/rubydb/sql/planner/binder.rb +550 -0
- data/lib/rubydb/sql/planner/type_checker.rb +431 -0
- data/lib/rubydb/sql/token.rb +210 -0
- data/lib/rubydb/storage/buffer_frame.rb +44 -0
- data/lib/rubydb/storage/buffer_pool.rb +155 -0
- data/lib/rubydb/storage/database_lock.rb +74 -0
- data/lib/rubydb/storage/deserializer.rb +342 -0
- data/lib/rubydb/storage/engine.rb +2338 -0
- data/lib/rubydb/storage/file_manager.rb +187 -0
- data/lib/rubydb/storage/free_space_map.rb +81 -0
- data/lib/rubydb/storage/page.rb +94 -0
- data/lib/rubydb/storage/page_allocator.rb +855 -0
- data/lib/rubydb/storage/page_header.rb +67 -0
- data/lib/rubydb/storage/page_manager.rb +131 -0
- data/lib/rubydb/storage/record.rb +58 -0
- data/lib/rubydb/storage/row.rb +78 -0
- data/lib/rubydb/storage/serializer.rb +51 -0
- data/lib/rubydb/storage/storage_layout.rb +151 -0
- data/lib/rubydb/storage/storage_manager.rb +114 -0
- data/lib/rubydb/storage/tuple.rb +461 -0
- data/lib/rubydb/storage/visibility_map.rb +984 -0
- data/lib/rubydb/transactions/commit_manager.rb +220 -0
- data/lib/rubydb/transactions/isolation.rb +98 -0
- data/lib/rubydb/transactions/lock.rb +76 -0
- data/lib/rubydb/transactions/lock_manager.rb +362 -0
- data/lib/rubydb/transactions/savepoint.rb +143 -0
- data/lib/rubydb/transactions/transaction.rb +215 -0
- data/lib/rubydb/transactions/transaction_id.rb +84 -0
- data/lib/rubydb/transactions/transaction_log.rb +257 -0
- data/lib/rubydb/transactions/transaction_manager.rb +435 -0
- data/lib/rubydb/types/bigint.rb +36 -0
- data/lib/rubydb/types/blob.rb +37 -0
- data/lib/rubydb/types/boolean.rb +34 -0
- data/lib/rubydb/types/date.rb +39 -0
- data/lib/rubydb/types/decimal.rb +48 -0
- data/lib/rubydb/types/float.rb +34 -0
- data/lib/rubydb/types/integer.rb +36 -0
- data/lib/rubydb/types/json.rb +41 -0
- data/lib/rubydb/types/null.rb +34 -0
- data/lib/rubydb/types/smallint.rb +36 -0
- data/lib/rubydb/types/text.rb +37 -0
- data/lib/rubydb/types/time.rb +46 -0
- data/lib/rubydb/types/timestamp.rb +39 -0
- data/lib/rubydb/types/type.rb +119 -0
- data/lib/rubydb/types/uuid.rb +47 -0
- data/lib/rubydb/types/varchar.rb +37 -0
- data/lib/rubydb/version.rb +33 -0
- data/lib/rubydb/wal/archive.rb +193 -0
- data/lib/rubydb/wal/checkpoint.rb +183 -0
- data/lib/rubydb/wal/lsn.rb +94 -0
- data/lib/rubydb/wal/reader.rb +260 -0
- data/lib/rubydb/wal/record.rb +105 -0
- data/lib/rubydb/wal/segment.rb +193 -0
- data/lib/rubydb/wal/wal.rb +452 -0
- data/lib/rubydb/wal/writer.rb +236 -0
- data/lib/rubydb.rb +7 -0
- data/packaging/docker/Dockerfile +36 -0
- data/packaging/docker/docker-compose.failover.yml +43 -0
- data/packaging/docker/entrypoint.sh +15 -0
- data/packaging/homebrew/rubydb.rb +19 -0
- data/packaging/systemd/rubydb.service +22 -0
- data/rubydb.gemspec +57 -0
- data/scripts/benchmark +7 -0
- data/scripts/durability_drill +37 -0
- data/scripts/format +0 -0
- data/scripts/fuzz +63 -0
- data/scripts/lint +0 -0
- data/scripts/release +50 -0
- data/scripts/release_check +43 -0
- data/scripts/replication_failover_drill +250 -0
- data/scripts/replication_network_failover_drill +255 -0
- data/scripts/restore_drill +45 -0
- data/scripts/security +0 -0
- data/scripts/setup +0 -0
- data/scripts/test +0 -0
- data/scripts/test-chaos +0 -0
- data/scripts/test-crash +0 -0
- data/scripts/test-integration +0 -0
- data/scripts/test-unit +0 -0
- data/visibility_map.json +1 -0
- metadata +538 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# RubyDB - A developer-first relational database for Ruby and Rails
|
|
4
|
+
#
|
|
5
|
+
# This is the main entry point for the RubyDB library.
|
|
6
|
+
# It provides the core database functionality and loads all required components.
|
|
7
|
+
|
|
8
|
+
require_relative "version"
|
|
9
|
+
require_relative "constants"
|
|
10
|
+
require_relative "build_info"
|
|
11
|
+
|
|
12
|
+
require_relative "errors/error"
|
|
13
|
+
require_relative "errors/connection_error"
|
|
14
|
+
require_relative "errors/database_error"
|
|
15
|
+
require_relative "errors/storage_error"
|
|
16
|
+
require_relative "errors/execution_error"
|
|
17
|
+
require_relative "errors/parser_error"
|
|
18
|
+
require_relative "errors/transaction_error"
|
|
19
|
+
require_relative "errors/client_error"
|
|
20
|
+
require_relative "errors/server_error"
|
|
21
|
+
|
|
22
|
+
require_relative "storage/database_lock"
|
|
23
|
+
require_relative "storage/engine"
|
|
24
|
+
require_relative "storage/storage_manager"
|
|
25
|
+
require_relative "storage/file_manager"
|
|
26
|
+
require_relative "storage/page"
|
|
27
|
+
require_relative "storage/page_header"
|
|
28
|
+
require_relative "storage/page_manager"
|
|
29
|
+
require_relative "storage/page_allocator"
|
|
30
|
+
require_relative "storage/buffer_pool"
|
|
31
|
+
require_relative "storage/buffer_frame"
|
|
32
|
+
require_relative "storage/record"
|
|
33
|
+
require_relative "storage/row"
|
|
34
|
+
require_relative "storage/tuple"
|
|
35
|
+
require_relative "storage/serializer"
|
|
36
|
+
require_relative "storage/deserializer"
|
|
37
|
+
require_relative "storage/free_space_map"
|
|
38
|
+
require_relative "storage/visibility_map"
|
|
39
|
+
require_relative "storage/storage_layout"
|
|
40
|
+
|
|
41
|
+
require_relative "sql/lexer"
|
|
42
|
+
require_relative "sql/token"
|
|
43
|
+
require_relative "sql/parser"
|
|
44
|
+
require_relative "sql/keywords"
|
|
45
|
+
require_relative "sql/operators"
|
|
46
|
+
require_relative "sql/ast/node"
|
|
47
|
+
require_relative "sql/ast/expression"
|
|
48
|
+
require_relative "sql/ast/select"
|
|
49
|
+
require_relative "sql/ast/with"
|
|
50
|
+
require_relative "sql/ast/set_operation"
|
|
51
|
+
require_relative "sql/ast/insert"
|
|
52
|
+
require_relative "sql/ast/update"
|
|
53
|
+
require_relative "sql/ast/delete"
|
|
54
|
+
require_relative "sql/ast/create_table"
|
|
55
|
+
require_relative "sql/ast/constraint"
|
|
56
|
+
require_relative "sql/ast/drop_table"
|
|
57
|
+
require_relative "sql/ast/create_index"
|
|
58
|
+
require_relative "sql/ast/drop_index"
|
|
59
|
+
require_relative "sql/ast/alter_table"
|
|
60
|
+
require_relative "sql/ast/create_database"
|
|
61
|
+
require_relative "sql/ast/drop_database"
|
|
62
|
+
require_relative "sql/ast/create_schema"
|
|
63
|
+
require_relative "sql/ast/drop_schema"
|
|
64
|
+
require_relative "sql/ast/view"
|
|
65
|
+
require_relative "sql/ast/trigger"
|
|
66
|
+
require_relative "sql/ast/vacuum"
|
|
67
|
+
require_relative "sql/ast/begin_transaction"
|
|
68
|
+
require_relative "sql/ast/commit"
|
|
69
|
+
require_relative "sql/ast/rollback"
|
|
70
|
+
require_relative "sql/ast/savepoint"
|
|
71
|
+
require_relative "sql/ast/explain"
|
|
72
|
+
require_relative "sql/planner/binder"
|
|
73
|
+
require_relative "sql/planner/analyzer"
|
|
74
|
+
require_relative "sql/planner/type_checker"
|
|
75
|
+
|
|
76
|
+
require_relative "execution/executor"
|
|
77
|
+
require_relative "execution/plan"
|
|
78
|
+
require_relative "execution/planner"
|
|
79
|
+
require_relative "execution/optimizer"
|
|
80
|
+
require_relative "execution/expression"
|
|
81
|
+
require_relative "execution/predicate"
|
|
82
|
+
require_relative "execution/scan"
|
|
83
|
+
require_relative "execution/sequential_scan"
|
|
84
|
+
require_relative "execution/index_scan"
|
|
85
|
+
require_relative "execution/insert_executor"
|
|
86
|
+
require_relative "execution/update_executor"
|
|
87
|
+
require_relative "execution/delete_executor"
|
|
88
|
+
require_relative "execution/join_executor"
|
|
89
|
+
require_relative "execution/aggregate_executor"
|
|
90
|
+
require_relative "execution/sort_executor"
|
|
91
|
+
require_relative "execution/limit_executor"
|
|
92
|
+
require_relative "execution/distinct_executor"
|
|
93
|
+
|
|
94
|
+
require_relative "catalog/catalog"
|
|
95
|
+
require_relative "catalog/database"
|
|
96
|
+
require_relative "catalog/schema"
|
|
97
|
+
require_relative "catalog/table"
|
|
98
|
+
require_relative "catalog/column"
|
|
99
|
+
require_relative "catalog/index"
|
|
100
|
+
require_relative "catalog/constraint"
|
|
101
|
+
require_relative "catalog/sequence"
|
|
102
|
+
require_relative "catalog/view"
|
|
103
|
+
require_relative "catalog/trigger"
|
|
104
|
+
require_relative "catalog/system_catalog"
|
|
105
|
+
|
|
106
|
+
require_relative "transactions/transaction"
|
|
107
|
+
require_relative "transactions/transaction_manager"
|
|
108
|
+
require_relative "transactions/transaction_id"
|
|
109
|
+
require_relative "transactions/lock_manager"
|
|
110
|
+
require_relative "transactions/lock"
|
|
111
|
+
require_relative "transactions/isolation"
|
|
112
|
+
require_relative "transactions/savepoint"
|
|
113
|
+
require_relative "errors/replication_error"
|
|
114
|
+
require_relative "transactions/commit_manager"
|
|
115
|
+
require_relative "transactions/transaction_log"
|
|
116
|
+
|
|
117
|
+
require_relative "indexes/index"
|
|
118
|
+
require_relative "indexes/btree"
|
|
119
|
+
require_relative "indexes/btree_node"
|
|
120
|
+
require_relative "indexes/btree_cursor"
|
|
121
|
+
require_relative "indexes/hash_index"
|
|
122
|
+
require_relative "indexes/index_scan"
|
|
123
|
+
require_relative "indexes/index_manager"
|
|
124
|
+
|
|
125
|
+
require_relative "wal/wal"
|
|
126
|
+
require_relative "wal/record"
|
|
127
|
+
require_relative "wal/writer"
|
|
128
|
+
require_relative "wal/reader"
|
|
129
|
+
require_relative "wal/segment"
|
|
130
|
+
require_relative "wal/checkpoint"
|
|
131
|
+
require_relative "wal/lsn"
|
|
132
|
+
require_relative "wal/archive"
|
|
133
|
+
|
|
134
|
+
require_relative "recovery/crash_recovery"
|
|
135
|
+
require_relative "recovery/checkpoint"
|
|
136
|
+
require_relative "recovery/redo"
|
|
137
|
+
require_relative "recovery/undo"
|
|
138
|
+
require_relative "recovery/consistency"
|
|
139
|
+
require_relative "recovery/corruption_detector"
|
|
140
|
+
require_relative "recovery/recovery_manager"
|
|
141
|
+
|
|
142
|
+
require_relative "mvcc/version"
|
|
143
|
+
require_relative "mvcc/visibility"
|
|
144
|
+
require_relative "mvcc/snapshot"
|
|
145
|
+
require_relative "mvcc/version_store"
|
|
146
|
+
require_relative "mvcc/vacuum"
|
|
147
|
+
require_relative "mvcc/garbage_collector"
|
|
148
|
+
|
|
149
|
+
require_relative "concurrency/scheduler"
|
|
150
|
+
require_relative "concurrency/latch"
|
|
151
|
+
require_relative "concurrency/mutex"
|
|
152
|
+
require_relative "concurrency/rw_lock"
|
|
153
|
+
require_relative "concurrency/deadlock_detector"
|
|
154
|
+
require_relative "concurrency/lock_graph"
|
|
155
|
+
require_relative "concurrency/worker_pool"
|
|
156
|
+
|
|
157
|
+
require_relative "constraints/constraint"
|
|
158
|
+
require_relative "constraints/primary_key"
|
|
159
|
+
require_relative "constraints/foreign_key"
|
|
160
|
+
require_relative "constraints/unique"
|
|
161
|
+
require_relative "constraints/not_null"
|
|
162
|
+
require_relative "constraints/check"
|
|
163
|
+
require_relative "constraints/validator"
|
|
164
|
+
|
|
165
|
+
require_relative "functions/function"
|
|
166
|
+
require_relative "functions/scalar"
|
|
167
|
+
require_relative "functions/aggregate"
|
|
168
|
+
require_relative "functions/string_functions"
|
|
169
|
+
require_relative "functions/numeric_functions"
|
|
170
|
+
require_relative "functions/date_functions"
|
|
171
|
+
require_relative "functions/json_functions"
|
|
172
|
+
require_relative "functions/system_functions"
|
|
173
|
+
|
|
174
|
+
require_relative "types/type"
|
|
175
|
+
require_relative "types/integer"
|
|
176
|
+
require_relative "types/bigint"
|
|
177
|
+
require_relative "types/smallint"
|
|
178
|
+
require_relative "types/float"
|
|
179
|
+
require_relative "types/decimal"
|
|
180
|
+
require_relative "types/boolean"
|
|
181
|
+
require_relative "types/text"
|
|
182
|
+
require_relative "types/varchar"
|
|
183
|
+
require_relative "types/blob"
|
|
184
|
+
require_relative "types/date"
|
|
185
|
+
require_relative "types/time"
|
|
186
|
+
require_relative "types/timestamp"
|
|
187
|
+
require_relative "types/json"
|
|
188
|
+
require_relative "types/uuid"
|
|
189
|
+
require_relative "types/null"
|
|
190
|
+
|
|
191
|
+
require_relative "security/authentication"
|
|
192
|
+
require_relative "security/authorization"
|
|
193
|
+
require_relative "security/password"
|
|
194
|
+
require_relative "security/credentials"
|
|
195
|
+
require_relative "security/user"
|
|
196
|
+
require_relative "security/role"
|
|
197
|
+
require_relative "security/permissions"
|
|
198
|
+
require_relative "security/access_control"
|
|
199
|
+
require_relative "security/audit_log"
|
|
200
|
+
|
|
201
|
+
require_relative "server/server"
|
|
202
|
+
require_relative "server/listener"
|
|
203
|
+
require_relative "server/connection"
|
|
204
|
+
require_relative "server/session"
|
|
205
|
+
require_relative "server/connection_pool"
|
|
206
|
+
require_relative "server/worker"
|
|
207
|
+
require_relative "server/request_handler"
|
|
208
|
+
require_relative "server/lifecycle"
|
|
209
|
+
|
|
210
|
+
require_relative "client/connection_url"
|
|
211
|
+
require_relative "client/client"
|
|
212
|
+
require_relative "client/connection"
|
|
213
|
+
require_relative "client/result"
|
|
214
|
+
require_relative "client/statement"
|
|
215
|
+
require_relative "client/prepared_statement"
|
|
216
|
+
require_relative "client/transaction"
|
|
217
|
+
require_relative "client/connection_pool"
|
|
218
|
+
|
|
219
|
+
require_relative "replication/primary"
|
|
220
|
+
require_relative "replication/replica"
|
|
221
|
+
require_relative "replication/replication_log"
|
|
222
|
+
require_relative "replication/replication_stream"
|
|
223
|
+
require_relative "replication/replication_manager"
|
|
224
|
+
require_relative "replication/replication_slot"
|
|
225
|
+
require_relative "replication/failover"
|
|
226
|
+
|
|
227
|
+
require_relative "backup/backup"
|
|
228
|
+
require_relative "backup/restore"
|
|
229
|
+
require_relative "backup/snapshot"
|
|
230
|
+
require_relative "backup/archive"
|
|
231
|
+
require_relative "backup/incremental"
|
|
232
|
+
require_relative "backup/verification"
|
|
233
|
+
|
|
234
|
+
require_relative "branching/branch"
|
|
235
|
+
require_relative "branching/branch_manager"
|
|
236
|
+
require_relative "branching/copy_on_write"
|
|
237
|
+
require_relative "branching/checkout"
|
|
238
|
+
require_relative "branching/merge"
|
|
239
|
+
require_relative "branching/diff"
|
|
240
|
+
require_relative "branching/branch_metadata"
|
|
241
|
+
|
|
242
|
+
require_relative "history/history"
|
|
243
|
+
require_relative "history/change"
|
|
244
|
+
require_relative "history/timeline"
|
|
245
|
+
require_relative "history/temporal_query"
|
|
246
|
+
require_relative "history/as_of"
|
|
247
|
+
require_relative "history/history_manager"
|
|
248
|
+
|
|
249
|
+
require_relative "migrations/migration"
|
|
250
|
+
require_relative "migrations/migration_manager"
|
|
251
|
+
require_relative "migrations/migration_version"
|
|
252
|
+
require_relative "migrations/schema_diff"
|
|
253
|
+
require_relative "migrations/schema_version"
|
|
254
|
+
require_relative "migrations/migration_lock"
|
|
255
|
+
|
|
256
|
+
require_relative "rails/adapter"
|
|
257
|
+
require_relative "rails/connection"
|
|
258
|
+
require_relative "rails/database_statements"
|
|
259
|
+
require_relative "rails/schema_statements"
|
|
260
|
+
require_relative "rails/quoting"
|
|
261
|
+
require_relative "rails/type"
|
|
262
|
+
require_relative "rails/migration"
|
|
263
|
+
require_relative "rails/transaction"
|
|
264
|
+
require_relative "rails/result"
|
|
265
|
+
|
|
266
|
+
require_relative "configuration/config"
|
|
267
|
+
require_relative "configuration/environment"
|
|
268
|
+
require_relative "configuration/defaults"
|
|
269
|
+
require_relative "configuration/parser"
|
|
270
|
+
require_relative "configuration/validation"
|
|
271
|
+
|
|
272
|
+
require_relative "monitoring/metrics"
|
|
273
|
+
require_relative "monitoring/statistics"
|
|
274
|
+
require_relative "monitoring/logger"
|
|
275
|
+
require_relative "monitoring/health"
|
|
276
|
+
require_relative "monitoring/performance"
|
|
277
|
+
require_relative "monitoring/events"
|
|
278
|
+
|
|
279
|
+
require_relative "cli/application"
|
|
280
|
+
require_relative "cli/formatter"
|
|
281
|
+
require_relative "cli/output"
|
|
282
|
+
require_relative "cli/commands/init"
|
|
283
|
+
require_relative "cli/commands/create"
|
|
284
|
+
require_relative "cli/commands/drop"
|
|
285
|
+
require_relative "cli/commands/start"
|
|
286
|
+
require_relative "cli/commands/stop"
|
|
287
|
+
require_relative "cli/commands/restart"
|
|
288
|
+
require_relative "cli/commands/status"
|
|
289
|
+
require_relative "cli/commands/shell"
|
|
290
|
+
require_relative "cli/commands/migrate"
|
|
291
|
+
require_relative "cli/commands/backup"
|
|
292
|
+
require_relative "cli/commands/restore"
|
|
293
|
+
require_relative "cli/commands/snapshot"
|
|
294
|
+
require_relative "cli/commands/branch"
|
|
295
|
+
require_relative "cli/commands/checkout"
|
|
296
|
+
require_relative "cli/commands/merge"
|
|
297
|
+
require_relative "cli/commands/diff"
|
|
298
|
+
require_relative "cli/commands/inspect"
|
|
299
|
+
require_relative "cli/commands/vacuum"
|
|
300
|
+
require_relative "cli/commands/doctor"
|
|
301
|
+
|
|
302
|
+
module RubyDB
|
|
303
|
+
# Main database class
|
|
304
|
+
class Database
|
|
305
|
+
attr_reader :path, :config, :engine, :connection
|
|
306
|
+
|
|
307
|
+
def initialize(path, config = {})
|
|
308
|
+
@path = path
|
|
309
|
+
@config = config
|
|
310
|
+
@engine = nil
|
|
311
|
+
@connection = nil
|
|
312
|
+
@is_open = false
|
|
313
|
+
@lock = Mutex.new
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
def connect
|
|
317
|
+
@lock.synchronize do
|
|
318
|
+
return self if @is_open
|
|
319
|
+
|
|
320
|
+
# Initialize storage engine
|
|
321
|
+
@engine = Storage::Engine.new(@path, @config)
|
|
322
|
+
|
|
323
|
+
# Initialize client connection
|
|
324
|
+
@connection = Client::Client.new(
|
|
325
|
+
database: @path,
|
|
326
|
+
host: @config[:host] || "localhost",
|
|
327
|
+
port: @config[:port] || 7432,
|
|
328
|
+
username: @config[:username] || "rubydb",
|
|
329
|
+
password: @config[:password] || "",
|
|
330
|
+
timeout: @config[:timeout] || 30,
|
|
331
|
+
pool_size: @config[:pool_size] || 1,
|
|
332
|
+
auto_connect: @config.fetch(:auto_connect, true)
|
|
333
|
+
)
|
|
334
|
+
@connection.connect if @config[:auto_connect] != false
|
|
335
|
+
|
|
336
|
+
@is_open = true
|
|
337
|
+
self
|
|
338
|
+
end
|
|
339
|
+
rescue => e
|
|
340
|
+
raise ConnectionError, "Failed to connect to database: #{e.message}"
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
def execute(sql)
|
|
344
|
+
ensure_connected
|
|
345
|
+
|
|
346
|
+
# Parse SQL
|
|
347
|
+
lexer = SQL::Lexer.new(sql)
|
|
348
|
+
tokens = lexer.tokenize
|
|
349
|
+
parser = SQL::Parser.new(tokens)
|
|
350
|
+
statements = parser.parse
|
|
351
|
+
|
|
352
|
+
results = []
|
|
353
|
+
statements.each do |stmt|
|
|
354
|
+
# Plan and execute
|
|
355
|
+
planner = Execution::Planner.new(@engine)
|
|
356
|
+
plan = planner.plan(stmt)
|
|
357
|
+
executor = Execution::Executor.new(@engine)
|
|
358
|
+
result = executor.execute(plan)
|
|
359
|
+
results << result
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
results.size == 1 ? results.first : results
|
|
363
|
+
rescue => e
|
|
364
|
+
raise ExecutionError, "Failed to execute SQL: #{e.message}"
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
def query(sql)
|
|
368
|
+
result = execute(sql)
|
|
369
|
+
if result.is_a?(Hash) && result[:rows]
|
|
370
|
+
result[:rows]
|
|
371
|
+
elsif result.is_a?(Array)
|
|
372
|
+
result.map { |r| r.is_a?(Hash) && r[:rows] ? r[:rows] : r }.flatten
|
|
373
|
+
else
|
|
374
|
+
[]
|
|
375
|
+
end
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def close
|
|
379
|
+
@lock.synchronize do
|
|
380
|
+
return true unless @is_open
|
|
381
|
+
|
|
382
|
+
@connection&.disconnect if @connection
|
|
383
|
+
@engine&.close if @engine
|
|
384
|
+
|
|
385
|
+
@is_open = false
|
|
386
|
+
@engine = nil
|
|
387
|
+
@connection = nil
|
|
388
|
+
true
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
|
|
392
|
+
def transaction(&block)
|
|
393
|
+
ensure_connected
|
|
394
|
+
|
|
395
|
+
begin
|
|
396
|
+
# Begin transaction
|
|
397
|
+
tx_id = @engine.begin_transaction
|
|
398
|
+
|
|
399
|
+
# Execute block
|
|
400
|
+
result = block.call if block_given?
|
|
401
|
+
|
|
402
|
+
# Commit transaction
|
|
403
|
+
@engine.commit_transaction(tx_id)
|
|
404
|
+
|
|
405
|
+
result
|
|
406
|
+
rescue => e
|
|
407
|
+
# Rollback on error
|
|
408
|
+
@engine.rollback_transaction(tx_id) if tx_id
|
|
409
|
+
raise TransactionError, "Transaction failed: #{e.message}"
|
|
410
|
+
end
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
def open?
|
|
414
|
+
@is_open
|
|
415
|
+
end
|
|
416
|
+
|
|
417
|
+
def stats
|
|
418
|
+
ensure_connected
|
|
419
|
+
@engine.stats
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def tables
|
|
423
|
+
ensure_connected
|
|
424
|
+
@engine.list_tables
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def create_table(name, &block)
|
|
428
|
+
ensure_connected
|
|
429
|
+
@engine.create_table(name, &block)
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def drop_table(name)
|
|
433
|
+
ensure_connected
|
|
434
|
+
@engine.drop_table(name)
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
def insert(table, data)
|
|
438
|
+
ensure_connected
|
|
439
|
+
columns = data.keys
|
|
440
|
+
values = data.values
|
|
441
|
+
@engine.insert_row(table, columns, values)
|
|
442
|
+
end
|
|
443
|
+
|
|
444
|
+
def select(table, conditions = {})
|
|
445
|
+
ensure_connected
|
|
446
|
+
columns = @engine.table_columns(table)
|
|
447
|
+
@engine.select_rows(table, columns, conditions)
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def update(table, id, data)
|
|
451
|
+
ensure_connected
|
|
452
|
+
@engine.update_row(table, id, data)
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
def delete(table, id)
|
|
456
|
+
ensure_connected
|
|
457
|
+
@engine.delete_row(table, id)
|
|
458
|
+
end
|
|
459
|
+
|
|
460
|
+
private
|
|
461
|
+
|
|
462
|
+
def ensure_connected
|
|
463
|
+
connect unless @is_open
|
|
464
|
+
raise DatabaseError, "Database is not open" unless @is_open
|
|
465
|
+
end
|
|
466
|
+
end
|
|
467
|
+
|
|
468
|
+
# Connect to a database
|
|
469
|
+
def self.connect(url)
|
|
470
|
+
# Parse URL: rubydb://local/./path/to/database.rdb
|
|
471
|
+
# rubydb://user:pass@host:7432/database
|
|
472
|
+
if url.start_with?("rubydb://local/")
|
|
473
|
+
path = url.sub("rubydb://local/", "")
|
|
474
|
+
Database.new(path).connect
|
|
475
|
+
elsif url.start_with?("rubydb://")
|
|
476
|
+
# Server mode
|
|
477
|
+
uri = URI.parse(url)
|
|
478
|
+
config = {
|
|
479
|
+
host: uri.host,
|
|
480
|
+
port: uri.port || 7432,
|
|
481
|
+
username: uri.user,
|
|
482
|
+
password: uri.password,
|
|
483
|
+
database: uri.path.sub("/", "")
|
|
484
|
+
}
|
|
485
|
+
db = Database.new(config[:database], config)
|
|
486
|
+
db.connect
|
|
487
|
+
db
|
|
488
|
+
else
|
|
489
|
+
# Treat as local path
|
|
490
|
+
Database.new(url).connect
|
|
491
|
+
end
|
|
492
|
+
rescue => e
|
|
493
|
+
raise ConnectionError, "Failed to connect: #{e.message}"
|
|
494
|
+
end
|
|
495
|
+
|
|
496
|
+
# Open a database file
|
|
497
|
+
def self.open(path, config = {})
|
|
498
|
+
db = Database.new(path, config)
|
|
499
|
+
db.connect
|
|
500
|
+
db
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
# Create a new database
|
|
504
|
+
def self.create(path, config = {})
|
|
505
|
+
# Ensure directory exists
|
|
506
|
+
dir = File.dirname(path)
|
|
507
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
|
508
|
+
|
|
509
|
+
# Create and initialize database
|
|
510
|
+
db = Database.new(path, config)
|
|
511
|
+
db.connect
|
|
512
|
+
|
|
513
|
+
# Create default schema
|
|
514
|
+
db.execute("CREATE TABLE IF NOT EXISTS schema_migrations (version TEXT PRIMARY KEY, applied_at TIMESTAMP)")
|
|
515
|
+
db.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT UNIQUE, email TEXT UNIQUE, created_at TIMESTAMP, updated_at TIMESTAMP)")
|
|
516
|
+
|
|
517
|
+
db
|
|
518
|
+
rescue => e
|
|
519
|
+
raise DatabaseError, "Failed to create database: #{e.message}"
|
|
520
|
+
end
|
|
521
|
+
|
|
522
|
+
# Version information
|
|
523
|
+
def self.version
|
|
524
|
+
VERSION
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
# Database information
|
|
528
|
+
def self.info
|
|
529
|
+
{
|
|
530
|
+
name: "RubyDB",
|
|
531
|
+
version: VERSION,
|
|
532
|
+
description: "A developer-first relational database for Ruby and Rails",
|
|
533
|
+
homepage: "https://github.com/rubydb/rubydb",
|
|
534
|
+
license: "MIT"
|
|
535
|
+
}
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
# Load a configuration file
|
|
539
|
+
def self.load_config(path)
|
|
540
|
+
Configuration::Config.load(path)
|
|
541
|
+
end
|
|
542
|
+
|
|
543
|
+
# Run migrations
|
|
544
|
+
def self.migrate(database, options = {})
|
|
545
|
+
manager = Migrations::MigrationManager.new(database, options)
|
|
546
|
+
manager.migrate
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
# Create a backup
|
|
550
|
+
def self.backup(database, options = {})
|
|
551
|
+
backup = Backup::Backup.new(database, options)
|
|
552
|
+
backup.create_backup
|
|
553
|
+
end
|
|
554
|
+
|
|
555
|
+
# Restore from backup
|
|
556
|
+
def self.restore(backup_path, options = {})
|
|
557
|
+
restore = Backup::Restore.new(nil, options)
|
|
558
|
+
restore.restore(backup_path)
|
|
559
|
+
end
|
|
560
|
+
end
|