conversion script compatible with the new DODB API
parent
95ca14e6b8
commit
0487a796f3
|
@ -5,17 +5,7 @@ class TodoD
|
||||||
end
|
end
|
||||||
|
|
||||||
class TodoD::List
|
class TodoD::List
|
||||||
enum PermissionLevel
|
alias PermissionLevel = ::AuthD::User::PermissionLevel
|
||||||
None = -1
|
|
||||||
Read
|
|
||||||
Post
|
|
||||||
Edit
|
|
||||||
Admin
|
|
||||||
|
|
||||||
def to_json(o)
|
|
||||||
to_s.downcase.to_json(o)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
JSON.mapping({
|
JSON.mapping({
|
||||||
id: String,
|
id: String,
|
||||||
|
@ -33,7 +23,6 @@ class TodoD::List
|
||||||
@permissions = {
|
@permissions = {
|
||||||
"admin" => [user.uid],
|
"admin" => [user.uid],
|
||||||
"edit" => [] of Int32,
|
"edit" => [] of Int32,
|
||||||
"post" => [] of Int32,
|
|
||||||
"read" => [] of Int32
|
"read" => [] of Int32
|
||||||
}
|
}
|
||||||
@tasks = [] of String
|
@tasks = [] of String
|
||||||
|
|
|
@ -2,27 +2,32 @@ require "option_parser"
|
||||||
require "uuid"
|
require "uuid"
|
||||||
require "uuid/json"
|
require "uuid/json"
|
||||||
|
|
||||||
|
require "ipc"
|
||||||
|
require "authd"
|
||||||
require "dodb"
|
require "dodb"
|
||||||
|
|
||||||
|
require "./todod.cr"
|
||||||
|
|
||||||
class TodoD::Storage
|
class TodoD::Storage
|
||||||
getter root : String
|
getter root : String
|
||||||
|
|
||||||
getter lists : DODB::DataBase(String, List)
|
getter lists : DODB::DataBase(List)
|
||||||
getter tasks : DODB::DataBase(String, Task)
|
getter lists_by_id : DODB::Index(List)
|
||||||
getter lists_per_user : DODB::Tags(List)
|
getter lists_per_user : DODB::Tags(List)
|
||||||
|
|
||||||
def initialize(@root)
|
getter tasks : DODB::DataBase(Task)
|
||||||
@lists = DODB::DataBase(String, List).new("#{@root}/lists")
|
getter tasks_by_id : DODB::Index(Task)
|
||||||
@lists_per_user = @lists.new_tags "user", &.users_with_read_permissions.map(&.to_s)
|
|
||||||
|
|
||||||
@tasks = DODB::DataBase(String, Task).new("#{@root}/tasks")
|
def initialize(@root)
|
||||||
|
@lists = DODB::DataBase(List).new("#{@root}/lists")
|
||||||
|
@lists_per_user = @lists.new_tags "user", &.users_with_read_permissions.map(&.to_s)
|
||||||
|
@lists_by_id = @lists.new_index "id", &.id
|
||||||
|
|
||||||
|
@tasks = DODB::DataBase(Task).new("#{@root}/tasks")
|
||||||
|
@tasks_by_id = @tasks.new_index "id", &.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_list(list)
|
def new_list(list)
|
||||||
@lists[list.id] = list
|
@lists << list
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,38 @@
|
||||||
require "json"
|
require "json"
|
||||||
require "./src/project.cr"
|
require "./src/project.cr"
|
||||||
|
|
||||||
|
require "option_parser"
|
||||||
|
|
||||||
require "./altsrc/common.cr"
|
require "./altsrc/common.cr"
|
||||||
require "./altsrc/main.cr"
|
require "./altsrc/main.cr"
|
||||||
|
|
||||||
|
new_storage_dir = "./new-storage"
|
||||||
|
old_storage_dir = "./old-storage"
|
||||||
|
|
||||||
|
OptionParser.parse do |parser|
|
||||||
|
parser.on "-n new-storage-directory",
|
||||||
|
"--new-directory storage-directory",
|
||||||
|
"The new directory where to put converted files." do |opt|
|
||||||
|
new_storage_dir = opt
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-o old-storage-directory",
|
||||||
|
"--old-storage-directory directory",
|
||||||
|
"Old storage directory, to convert." do |opt|
|
||||||
|
old_storage_dir = opt
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.on "-h", "--help", "Show this help" do
|
||||||
|
puts parser
|
||||||
|
puts "Default values are:"
|
||||||
|
pp! new_storage_dir
|
||||||
|
pp! old_storage_dir
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# 1. get the old list of projects
|
# 1. get the old list of projects
|
||||||
old_storage = Project.all "../storage/"
|
old_storage = Project.all old_storage_dir
|
||||||
|
|
||||||
# PROJECT: JSON.mapping({
|
# PROJECT: JSON.mapping({
|
||||||
# PROJECT: id: String,
|
# PROJECT: id: String,
|
||||||
|
@ -30,7 +56,7 @@ old_storage = Project.all "../storage/"
|
||||||
# TASKS: })
|
# TASKS: })
|
||||||
|
|
||||||
# 2. create the new storage
|
# 2. create the new storage
|
||||||
new_storage = TodoD::Storage.new "../new-storage/"
|
new_storage = TodoD::Storage.new new_storage_dir
|
||||||
|
|
||||||
|
|
||||||
# 3. for each project (old name for "list")
|
# 3. for each project (old name for "list")
|
||||||
|
@ -91,7 +117,7 @@ old_storage.each do |old_project|
|
||||||
|
|
||||||
# 3. store the new task
|
# 3. store the new task
|
||||||
tasks << newtask
|
tasks << newtask
|
||||||
new_storage.tasks[newtask.id] = newtask
|
new_storage.tasks << newtask
|
||||||
end
|
end
|
||||||
|
|
||||||
# finally, create the list with all the parameters
|
# finally, create the list with all the parameters
|
||||||
|
@ -105,5 +131,5 @@ old_storage.each do |old_project|
|
||||||
pp! list
|
pp! list
|
||||||
|
|
||||||
# finally, store the new list
|
# finally, store the new list
|
||||||
new_storage.lists[list.id] = list
|
new_storage.lists << list
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue