conversion script compatible with the new DODB API

master
Philippe PITTOLI 2020-01-16 20:30:43 +01:00
parent 95ca14e6b8
commit 0487a796f3
3 changed files with 46 additions and 26 deletions

View File

@ -5,17 +5,7 @@ class TodoD
end
class TodoD::List
enum PermissionLevel
None = -1
Read
Post
Edit
Admin
def to_json(o)
to_s.downcase.to_json(o)
end
end
alias PermissionLevel = ::AuthD::User::PermissionLevel
JSON.mapping({
id: String,
@ -33,7 +23,6 @@ class TodoD::List
@permissions = {
"admin" => [user.uid],
"edit" => [] of Int32,
"post" => [] of Int32,
"read" => [] of Int32
}
@tasks = [] of String

View File

@ -2,27 +2,32 @@ require "option_parser"
require "uuid"
require "uuid/json"
require "ipc"
require "authd"
require "dodb"
require "./todod.cr"
class TodoD::Storage
getter root : String
getter lists : DODB::DataBase(String, List)
getter tasks : DODB::DataBase(String, Task)
getter lists : DODB::DataBase(List)
getter lists_by_id : DODB::Index(List)
getter lists_per_user : DODB::Tags(List)
def initialize(@root)
@lists = DODB::DataBase(String, List).new("#{@root}/lists")
@lists_per_user = @lists.new_tags "user", &.users_with_read_permissions.map(&.to_s)
getter tasks : DODB::DataBase(Task)
getter tasks_by_id : DODB::Index(Task)
@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
def new_list(list)
@lists[list.id] = list
@lists << list
end
end

View File

@ -2,12 +2,38 @@
require "json"
require "./src/project.cr"
require "option_parser"
require "./altsrc/common.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
old_storage = Project.all "../storage/"
old_storage = Project.all old_storage_dir
# PROJECT: JSON.mapping({
# PROJECT: id: String,
@ -30,7 +56,7 @@ old_storage = Project.all "../storage/"
# TASKS: })
# 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")
@ -91,7 +117,7 @@ old_storage.each do |old_project|
# 3. store the new task
tasks << newtask
new_storage.tasks[newtask.id] = newtask
new_storage.tasks << newtask
end
# finally, create the list with all the parameters
@ -105,5 +131,5 @@ old_storage.each do |old_project|
pp! list
# finally, store the new list
new_storage.lists[list.id] = list
new_storage.lists << list
end