* [PATCH] dtas-mlib: initial commit
@ 2015-11-07 7:55 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-11-07 7:55 UTC (permalink / raw)
To: spew
---
lib/dtas/mlib.rb | 13 +++++++++
lib/dtas/mlib/migrations/0001_initial.rb | 50 ++++++++++++++++++++++++++++++++
test/test_mlib.rb | 24 +++++++++++++++
3 files changed, 87 insertions(+)
create mode 100644 lib/dtas/mlib.rb
create mode 100644 lib/dtas/mlib/migrations/0001_initial.rb
create mode 100644 test/test_mlib.rb
diff --git a/lib/dtas/mlib.rb b/lib/dtas/mlib.rb
new file mode 100644
index 0000000..bd35321
--- /dev/null
+++ b/lib/dtas/mlib.rb
@@ -0,0 +1,13 @@
+# Copyright (C) 2015 all contributors <dtas-all@nongnu.org>
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+
+require 'sequel'
+require_relative '../dtas'
+require 'rubygems' # we use Gem.load_path
+module DTAS::Mlib
+ def self.setup(db)
+ migdir = "#{File.dirname(__FILE__)}/mlib/migrations"
+ Sequel.extension :migration, :core_extensions # ugh..
+ Sequel::Migrator.apply(db, migdir)
+ end
+end
diff --git a/lib/dtas/mlib/migrations/0001_initial.rb b/lib/dtas/mlib/migrations/0001_initial.rb
new file mode 100644
index 0000000..7cae034
--- /dev/null
+++ b/lib/dtas/mlib/migrations/0001_initial.rb
@@ -0,0 +1,50 @@
+# Copyright (C) 2015 all contributors <dtas-all@nongnu.org>
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+
+Sequel.migration do
+ up do
+ create_table(:settings) do
+ primary_key :id
+ String :name, null: false, unique: true
+ String :value
+ end
+
+ create_table(:paths) do
+ primary_key :id
+ String :name, null: false
+ Integer :parent_id, null: false # parent dir
+ Integer :ctime, null: false
+ Integer :length, null: false # length of track
+ TrueClass :dir, default: false
+ unique [ :parent_id, :name ]
+ index :parent_id
+ end
+
+ create_table(:tags) do
+ primary_key :id
+ String :tag, null: false, unique: true
+ end
+
+ create_table(:values) do
+ primary_key :id
+ String :value, null: false, unique: true
+ end
+
+ create_table(:comments) do
+ Integer :path_id, null: false
+ Integer :tag_id, null: false
+ Integer :value_id, null: false
+ primary_key [ :path_id, :tag_id, :value_id ]
+ index :path_id
+ index [ :tag_id, :value_id ]
+ end
+ end
+
+ down do
+ drop_table(:settings)
+ drop_table(:paths)
+ drop_table(:tags)
+ drop_table(:values)
+ drop_table(:comments)
+ end
+end
diff --git a/test/test_mlib.rb b/test/test_mlib.rb
new file mode 100644
index 0000000..b3d8133
--- /dev/null
+++ b/test/test_mlib.rb
@@ -0,0 +1,24 @@
+# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative 'helper'
+begin
+ require 'dtas/mlib'
+ require 'sequel/no_core_ext'
+ require 'sqlite3'
+rescue LoadError => err
+ warn "skipping mlib test: #{err.message}"
+ exit 0
+end
+require 'tempfile'
+
+class TestBuffer < Testcase
+ def test_setup
+ Tempfile.create(%w(tmp .sqlite3)) do |tmp|
+ path = tmp.path
+ db = Sequel.connect("sqlite://#{path}?synchronous=off")
+ $-w = false;
+ DTAS::Mlib.setup(db)
+ assert_operator File.size(path), :>, 0
+ end
+ end
+end
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-11-07 7:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-07 7:55 [PATCH] dtas-mlib: initial commit Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).