2023-12-08 17:28:45 +01:00
|
|
|
# frozen_string_literal: true
|
2023-12-24 20:15:46 +01:00
|
|
|
|
2023-12-08 17:28:45 +01:00
|
|
|
module Twenty
|
2024-01-09 00:48:37 +01:00
|
|
|
require "fileutils"
|
|
|
|
require "active_record"
|
2024-02-16 08:46:49 +01:00
|
|
|
require_relative "twenty-server/path"
|
2024-02-16 02:23:10 +01:00
|
|
|
require_relative "twenty-server/graphql"
|
2024-03-27 22:18:58 +01:00
|
|
|
require_relative "twenty-server/rack"
|
2024-02-16 02:23:10 +01:00
|
|
|
require_relative "twenty-server/migration"
|
|
|
|
require_relative "twenty-server/model"
|
2024-01-28 03:49:40 +01:00
|
|
|
extend FileUtils
|
2024-02-16 08:46:49 +01:00
|
|
|
extend Path
|
2024-01-07 09:51:08 +01:00
|
|
|
|
2024-01-09 00:48:37 +01:00
|
|
|
##
|
|
|
|
# @return [String]
|
2024-01-28 03:49:40 +01:00
|
|
|
# Returns the location of the default SQLite database.
|
2024-01-09 01:10:32 +01:00
|
|
|
def self.default_database
|
2024-02-16 08:46:49 +01:00
|
|
|
@default_database ||= File.join(datadir, "database.sqlite")
|
2024-01-09 00:48:37 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Establishes a database connection.
|
|
|
|
#
|
|
|
|
# @param [String] path
|
|
|
|
# The path to a SQLite3 database file.
|
|
|
|
#
|
|
|
|
# @return [void]
|
|
|
|
def self.establish_connection(path:)
|
|
|
|
ActiveRecord::Base.establish_connection(
|
|
|
|
adapter: "sqlite3",
|
|
|
|
database: path,
|
2024-01-12 07:45:51 +01:00
|
|
|
pool: 16
|
2024-01-09 00:48:37 +01:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Prepares the parent directory of the database.
|
|
|
|
# @return [void]
|
|
|
|
# @api private
|
|
|
|
def self.prepare_dir
|
2024-02-16 08:46:49 +01:00
|
|
|
mkdir_p(datadir)
|
|
|
|
mkdir_p(tmpdir)
|
2024-01-28 03:49:40 +01:00
|
|
|
touch(default_database)
|
2024-01-09 00:48:37 +01:00
|
|
|
rescue => ex
|
|
|
|
warn "prepare_dir error: #{ex.message} (#{ex.class})"
|
|
|
|
end
|
|
|
|
private_class_method :prepare_dir
|
|
|
|
prepare_dir
|
2023-12-08 17:28:45 +01:00
|
|
|
end
|