Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4a370f9d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4a370f9d
编写于
3月 28, 2013
作者:
K
kennyj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract Firebird database tasks.
上级
196af50e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
151 addition
and
20 deletion
+151
-20
activerecord/lib/active_record.rb
activerecord/lib/active_record.rb
+2
-0
activerecord/lib/active_record/railties/databases.rake
activerecord/lib/active_record/railties/databases.rake
+0
-20
activerecord/lib/active_record/tasks/database_tasks.rb
activerecord/lib/active_record/tasks/database_tasks.rb
+1
-0
activerecord/lib/active_record/tasks/firebird_database_tasks.rb
...record/lib/active_record/tasks/firebird_database_tasks.rb
+55
-0
activerecord/test/cases/tasks/firebird_rake_test.rb
activerecord/test/cases/tasks/firebird_rake_test.rb
+93
-0
未找到文件。
activerecord/lib/active_record.rb
浏览文件 @
4a370f9d
...
...
@@ -143,6 +143,8 @@ module Tasks
autoload
:MySQLDatabaseTasks
,
'active_record/tasks/mysql_database_tasks'
autoload
:PostgreSQLDatabaseTasks
,
'active_record/tasks/postgresql_database_tasks'
autoload
:FirebirdDatabaseTasks
,
'active_record/tasks/firebird_database_tasks'
end
autoload
:TestCase
...
...
activerecord/lib/active_record/railties/databases.rake
浏览文件 @
4a370f9d
...
...
@@ -270,15 +270,6 @@ db_namespace = namespace :db do
end
namespace
:structure
do
def
set_firebird_env
(
config
)
ENV
[
'ISC_USER'
]
=
config
[
'username'
].
to_s
if
config
[
'username'
]
ENV
[
'ISC_PASSWORD'
]
=
config
[
'password'
].
to_s
if
config
[
'password'
]
end
def
firebird_db_string
(
config
)
FireRuby
::
Database
.
db_string_for
(
config
.
symbolize_keys
)
end
desc
'Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql'
task
:dump
=>
[
:environment
,
:load_config
]
do
filename
=
ENV
[
'DB_STRUCTURE'
]
||
File
.
join
(
Rails
.
root
,
"db"
,
"structure.sql"
)
...
...
@@ -289,10 +280,6 @@ db_namespace = namespace :db do
File
.
open
(
filename
,
"w:utf-8"
)
{
|
f
|
f
<<
ActiveRecord
::
Base
.
connection
.
structure_dump
}
when
'sqlserver'
`smoscript -s
#{
current_config
[
'host'
]
}
-d
#{
current_config
[
'database'
]
}
-u
#{
current_config
[
'username'
]
}
-p
#{
current_config
[
'password'
]
}
-f
#{
filename
}
-A -U`
when
"firebird"
set_firebird_env
(
current_config
)
db_string
=
firebird_db_string
(
current_config
)
sh
"isql -a
#{
db_string
}
>
#{
filename
}
"
else
ActiveRecord
::
Tasks
::
DatabaseTasks
.
structure_dump
(
current_config
,
filename
)
end
...
...
@@ -317,10 +304,6 @@ db_namespace = namespace :db do
IO
.
read
(
filename
).
split
(
";
\n\n
"
).
each
do
|
ddl
|
ActiveRecord
::
Base
.
connection
.
execute
(
ddl
)
end
when
'firebird'
set_firebird_env
(
current_config
)
db_string
=
firebird_db_string
(
current_config
)
sh
"isql -i
#{
filename
}
#{
db_string
}
"
else
ActiveRecord
::
Tasks
::
DatabaseTasks
.
structure_load
(
current_config
,
filename
)
end
...
...
@@ -391,9 +374,6 @@ db_namespace = namespace :db do
ActiveRecord
::
Base
.
connection
.
structure_drop
.
split
(
";
\n\n
"
).
each
do
|
ddl
|
ActiveRecord
::
Base
.
connection
.
execute
(
ddl
)
end
when
'firebird'
ActiveRecord
::
Base
.
establish_connection
(
:test
)
ActiveRecord
::
Base
.
connection
.
recreate_database!
else
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge
abcs
[
'test'
]
end
...
...
activerecord/lib/active_record/tasks/database_tasks.rb
浏览文件 @
4a370f9d
...
...
@@ -18,6 +18,7 @@ def register_task(pattern, task)
register_task
(
/mysql/
,
ActiveRecord
::
Tasks
::
MySQLDatabaseTasks
)
register_task
(
/postgresql/
,
ActiveRecord
::
Tasks
::
PostgreSQLDatabaseTasks
)
register_task
(
/sqlite/
,
ActiveRecord
::
Tasks
::
SQLiteDatabaseTasks
)
register_task
(
/firebird/
,
ActiveRecord
::
Tasks
::
FirebirdDatabaseTasks
)
def
current_config
(
options
=
{})
options
.
reverse_merge!
:env
=>
Rails
.
env
...
...
activerecord/lib/active_record/tasks/firebird_database_tasks.rb
0 → 100644
浏览文件 @
4a370f9d
module
ActiveRecord
module
Tasks
# :nodoc:
class
FirebirdDatabaseTasks
# :nodoc:
delegate
:connection
,
:establish_connection
,
to:
ActiveRecord
::
Base
def
initialize
(
configuration
)
@configuration
=
configuration
end
def
create
$stderr
.
puts
'sorry, your database adapter is not supported yet, feel free to submit a patch'
end
def
drop
$stderr
.
puts
'sorry, your database adapter is not supported yet, feel free to submit a patch'
end
def
purge
establish_connection
(
:test
)
connection
.
recreate_database!
end
def
charset
$stderr
.
puts
'sorry, your database adapter is not supported yet, feel free to submit a patch'
end
def
structure_dump
(
filename
)
set_firebird_env
(
configuration
)
db_string
=
firebird_db_string
(
configuration
)
Kernel
.
system
"isql -a
#{
db_string
}
>
#{
filename
}
"
end
def
structure_load
(
filename
)
set_firebird_env
(
configuration
)
db_string
=
firebird_db_string
(
configuration
)
Kernel
.
system
"isql -i
#{
filename
}
#{
db_string
}
"
end
private
def
set_firebird_env
(
config
)
ENV
[
'ISC_USER'
]
=
config
[
'username'
].
to_s
if
config
[
'username'
]
ENV
[
'ISC_PASSWORD'
]
=
config
[
'password'
].
to_s
if
config
[
'password'
]
end
def
firebird_db_string
(
config
)
FireRuby
::
Database
.
db_string_for
(
config
.
symbolize_keys
)
end
def
configuration
@configuration
end
end
end
end
activerecord/test/cases/tasks/firebird_rake_test.rb
0 → 100644
浏览文件 @
4a370f9d
require
'cases/helper'
unless
defined?
(
FireRuby
::
Database
)
module
FireRuby
module
Database
;
end
end
end
module
ActiveRecord
module
FirebirdSetupper
def
setup
@database
=
'db.firebird'
@connection
=
stub
:connection
@configuration
=
{
'adapter'
=>
'firebird'
,
'database'
=>
@database
}
ActiveRecord
::
Base
.
stubs
(
:connection
).
returns
(
@connection
)
ActiveRecord
::
Base
.
stubs
(
:establish_connection
).
returns
(
true
)
end
end
class
FirebirdDBCreateTest
<
ActiveRecord
::
TestCase
include
FirebirdSetupper
def
test_db_retrieves_create
message
=
capture
(
:stderr
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
create
@configuration
end
assert_match
(
/not supported/
,
message
)
end
end
class
FirebirdDBDropTest
<
ActiveRecord
::
TestCase
include
FirebirdSetupper
def
test_db_retrieves_drop
message
=
capture
(
:stderr
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
drop
@configuration
end
assert_match
(
/not supported/
,
message
)
end
end
class
FirebirdDBCharsetAndCollationTest
<
ActiveRecord
::
TestCase
include
FirebirdSetupper
def
test_db_retrieves_collation
assert_raise
NoMethodError
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
collation
@configuration
end
end
def
test_db_retrieves_charset
message
=
capture
(
:stderr
)
do
ActiveRecord
::
Tasks
::
DatabaseTasks
.
charset
@configuration
end
assert_match
(
/not supported/
,
message
)
end
end
class
FirebirdStructureDumpTest
<
ActiveRecord
::
TestCase
include
FirebirdSetupper
def
setup
super
FireRuby
::
Database
.
stubs
(
:db_string_for
).
returns
(
@database
)
end
def
test_structure_dump
filename
=
"filebird.sql"
Kernel
.
expects
(
:system
).
with
(
"isql -a
#{
@database
}
>
#{
filename
}
"
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
structure_dump
(
@configuration
,
filename
)
end
end
class
FirebirdStructureLoadTest
<
ActiveRecord
::
TestCase
include
FirebirdSetupper
def
setup
super
FireRuby
::
Database
.
stubs
(
:db_string_for
).
returns
(
@database
)
end
def
test_structure_load
filename
=
"firebird.sql"
Kernel
.
expects
(
:system
).
with
(
"isql -i
#{
filename
}
#{
@database
}
"
)
ActiveRecord
::
Tasks
::
DatabaseTasks
.
structure_load
(
@configuration
,
filename
)
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录