Class: ActiveRecord::Tasks::TursoDatabaseTasks
- Inherits:
-
SQLiteDatabaseTasks
- Object
- SQLiteDatabaseTasks
- ActiveRecord::Tasks::TursoDatabaseTasks
- Defined in:
- lib/active_record/tasks/turso_database_tasks.rb
Instance Method Summary collapse
- #charset ⇒ Object
- #charset_collation ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(db_config, root = nil) ⇒ TursoDatabaseTasks
constructor
A new instance of TursoDatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename, extra_flags) ⇒ Object
- #structure_load(filename, extra_flags) ⇒ Object
Constructor Details
#initialize(db_config, root = nil) ⇒ TursoDatabaseTasks
Returns a new instance of TursoDatabaseTasks.
8 9 10 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 8 def initialize(db_config, root = nil) @configuration = db_config end |
Instance Method Details
#charset ⇒ Object
37 38 39 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 37 def charset "UTF-8" end |
#charset_collation ⇒ Object
41 42 43 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 41 def charset_collation nil end |
#create ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 12 def create path = configuration.database return if path == ":memory:" FileUtils.mkdir_p(File.dirname(path)) establish_connection(configuration) connection.execute("SELECT 1") end |
#drop ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 21 def drop path = configuration.database return if path == ":memory:" disconnect! FileUtils.rm_f(path) FileUtils.rm_f("#{path}-wal") FileUtils.rm_f("#{path}-shm") FileUtils.rm_f(mvcc_log_path(path)) end |
#purge ⇒ Object
32 33 34 35 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 32 def purge drop create end |
#structure_dump(filename, extra_flags) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 45 def structure_dump(filename, extra_flags) establish_connection(configuration) io = File.open(filename, "w") io.puts("PRAGMA foreign_keys = OFF;") tables = connection.query_values(" SELECT name FROM sqlite_master\n WHERE type = 'table'\n AND name NOT LIKE 'sqlite_%'\n AND name NOT LIKE '__turso_internal_%'\n ORDER BY name\n SQL\n\n tables.each do |table|\n sql = connection.query_value(<<~SQL, \"SCHEMA\")\n SELECT sql FROM sqlite_master WHERE name = \#{connection.quote(table)}\n SQL\n io.puts(\"\#{sql};\") if sql\n end\n\n indexes = connection.query_values(<<~SQL, \"SCHEMA\")\n SELECT name FROM sqlite_master\n WHERE type = 'index'\n AND name NOT LIKE 'sqlite_%'\n AND name NOT LIKE '__turso_internal_%'\n AND sql IS NOT NULL\n ORDER BY name\n SQL\n\n indexes.each do |index|\n sql = connection.query_value(<<~SQL, \"SCHEMA\")\n SELECT sql FROM sqlite_master WHERE name = \#{connection.quote(index)}\n SQL\n io.puts(\"\#{sql};\") if sql\n end\n\n views = connection.query_values(<<~SQL, \"SCHEMA\")\n SELECT name FROM sqlite_master\n WHERE type = 'view'\n AND name NOT LIKE 'sqlite_%'\n ORDER BY name\n SQL\n\n views.each do |view|\n sql = connection.query_value(<<~SQL, \"SCHEMA\")\n SELECT sql FROM sqlite_master WHERE name = \#{connection.quote(view)}\n SQL\n io.puts(\"\#{sql};\") if sql\n end\n\n io.puts(\"PRAGMA foreign_keys = ON;\")\n io.close\nend\n", "SCHEMA") |
#structure_load(filename, extra_flags) ⇒ Object
99 100 101 102 103 |
# File 'lib/active_record/tasks/turso_database_tasks.rb', line 99 def structure_load(filename, extra_flags) establish_connection(configuration) sql = File.read(filename) ActiveRecord::Base.connection.raw_connection.execute_batch(sql) end |