s|establish_connection|connect|g
This commit is contained in:
parent
27ce4251ac
commit
4f162796b0
12 changed files with 29 additions and 15 deletions
|
@ -21,7 +21,7 @@ class Twenty::Command::Connect < Twenty::Command
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_command(options)
|
def run_command(options)
|
||||||
path = File.realpath(options.path ? options.path : Dir.getwd)
|
path = File.realpath(options.path || Dir.getwd)
|
||||||
if File.exist?(path)
|
if File.exist?(path)
|
||||||
require_models!
|
require_models!
|
||||||
project = Twenty::Project.create(
|
project = Twenty::Project.create(
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Twenty::Command::Disconnect < Twenty::Command
|
||||||
private
|
private
|
||||||
|
|
||||||
def run_command(options)
|
def run_command(options)
|
||||||
path = File.realpath(options.path ? options.path : Dir.getwd)
|
path = File.realpath(options.path || Dir.getwd)
|
||||||
require_models!
|
require_models!
|
||||||
Twenty::Project
|
Twenty::Project
|
||||||
.where(path:)
|
.where(path:)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Twenty::Command::Hook
|
module Twenty::Command::Hook
|
||||||
require_relative "hook/require_migration"
|
require_relative "hook/require_migration"
|
||||||
require_relative "hook/sqlite_conn"
|
require_relative "hook/sqlite_conn"
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Twenty::Command::Hook
|
||||||
private
|
private
|
||||||
|
|
||||||
def format_backtrace(backtrace)
|
def format_backtrace(backtrace)
|
||||||
backtrace[0..FRAME_MAX-1].map do
|
backtrace[0..FRAME_MAX - 1].map do
|
||||||
[" " * INDENT_BY, _1.gsub(Dir.getwd, "")].join
|
[" " * INDENT_BY, _1.gsub(Dir.getwd, "")].join
|
||||||
end.join("\n")
|
end.join("\n")
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,16 @@
|
||||||
module Twenty::Command::Hook
|
module Twenty::Command::Hook
|
||||||
module SQLiteConn
|
module SQLiteConn
|
||||||
def run_command(options)
|
def run_command(options)
|
||||||
path = options.database || Twenty.default_database
|
connect!(options)
|
||||||
Twenty.establish_connection(path:)
|
|
||||||
super(options)
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def connect!(options)
|
||||||
|
Twenty.connect(
|
||||||
|
database: options.database || Twenty.default_database
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Twenty::Command::Option
|
module Twenty::Command::Option
|
||||||
require_relative "option/database"
|
require_relative "option/database"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Twenty::Command::Option
|
module Twenty::Command::Option
|
||||||
module Database
|
module Database
|
||||||
def self.included(mod)
|
def self.included(mod)
|
||||||
|
|
|
@ -42,22 +42,19 @@ module Twenty
|
||||||
##
|
##
|
||||||
# Establishes a database connection
|
# Establishes a database connection
|
||||||
#
|
#
|
||||||
# @param [String] path
|
# @param [Hash] options
|
||||||
# The path to a SQLite database
|
# 'Sequel.connect' options
|
||||||
#
|
#
|
||||||
# @return [void]
|
# @return [void]
|
||||||
def self.establish_connection(path:)
|
def self.connect(options = {})
|
||||||
@db = Sequel.connect(
|
@db = Sequel.connect({adapter: "sqlite"}.merge(options))
|
||||||
adapter: "sqlite",
|
|
||||||
database: path
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @return [Sequel::Database::SQLite]
|
# @return [Sequel::Database::SQLite]
|
||||||
# Returns a database object
|
# Returns a database object
|
||||||
def self.db
|
def self.db
|
||||||
establish_connection unless @db
|
connect unless @db
|
||||||
@db
|
@db
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,6 @@ module Twenty::Migration
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
# Returns true when there are pending migrations
|
# Returns true when there are pending migrations
|
||||||
def self.pending_migrations?
|
def self.pending_migrations?
|
||||||
! Sequel::Migrator.is_current?(Twenty.db, migrations_path)
|
!Sequel::Migrator.is_current?(Twenty.db, migrations_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
Sequel.migration do
|
Sequel.migration do
|
||||||
column_exists = ->(table, column) do
|
column_exists = ->(table, column) do
|
||||||
schema = Twenty.db.schema(table)
|
schema = Twenty.db.schema(table)
|
||||||
schema.find { |(key,_)| key == column }
|
schema.find { |(key, _)| key == column }
|
||||||
end
|
end
|
||||||
|
|
||||||
up do
|
up do
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Twenty::Mixin
|
module Twenty::Mixin
|
||||||
require_relative "mixin/colorable"
|
require_relative "mixin/colorable"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Twenty
|
module Twenty
|
||||||
class Milestone < Sequel::Model
|
class Milestone < Sequel::Model
|
||||||
include Model
|
include Model
|
||||||
|
|
Loading…
Reference in a new issue