flattendb 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to flattendb version 0.0.4
5
+ This documentation refers to flattendb version 0.0.5
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -26,7 +26,7 @@ Rubyforge project:: <http://rubyforge.org/projects/prometheus>
26
26
 
27
27
  == LICENSE AND COPYRIGHT
28
28
 
29
- Copyright (C) 2007 University of Cologne,
29
+ Copyright (C) 2007-2010 University of Cologne,
30
30
  Albertus-Magnus-Platz, 50932 Cologne, Germany
31
31
 
32
32
  flattendb is free software: you can redistribute it and/or modify it under the
data/Rakefile CHANGED
@@ -8,7 +8,8 @@ require 'lib/flattendb/version'
8
8
 
9
9
  Hen.lay! {{
10
10
  :rubyforge => {
11
- :package => 'flattendb'
11
+ :project => %q{prometheus},
12
+ :package => %q{flattendb}
12
13
  },
13
14
 
14
15
  :gem => {
data/bin/flattendb.mdb CHANGED
@@ -1,7 +1,5 @@
1
1
  #! /usr/bin/ruby
2
2
 
3
- # vi:ft=ruby
4
-
5
3
  #--
6
4
  ###############################################################################
7
5
  # #
@@ -53,3 +51,5 @@ else
53
51
  }
54
52
  end
55
53
  end
54
+
55
+ # vim:ft=ruby
data/bin/flattendb.mysql CHANGED
@@ -1,7 +1,5 @@
1
1
  #! /usr/bin/ruby
2
2
 
3
- # vi:ft=ruby
4
-
5
3
  #--
6
4
  ###############################################################################
7
5
  # #
@@ -42,7 +40,7 @@ else
42
40
  abort "Input file doesn't seem to be a valid XML file, XML declaration missing"
43
41
  end
44
42
  when :sql
45
- $dump_file = $infile.sub(/\.(?:sql|dump)$/i, '') << '.xml'
43
+ $dump_file = $infile.sub(/\.(?:sql|dump)(?:\.gz)?\z/i, '') << '.xml'
46
44
  abort "Dump file and output file are the same: #{$dump_file} = #{$outfile}" \
47
45
  if File.expand_path($dump_file) == File.expand_path($outfile)
48
46
 
@@ -54,34 +52,35 @@ else
54
52
 
55
53
  mysql_user = ask('Please enter the MySQL user name: ') \
56
54
  { |q| q.default = ENV['USER'] }
57
- mysql_pass = ask("Please enter the MySQL password for that user: ") \
55
+ mysql_pass = ask('Please enter the MySQL password for that user: ') \
58
56
  { |q| q.echo = false }
59
57
 
60
- # according to <http://www.adamspiers.org/computing/mysqldiff/#how> MySQL
61
- # default permissions allow anyone to create databases beginning with the
62
- # prefix 'test_'
63
- temp_db = 'flattendb_temp_%d_%d' % [Time.now, $$]
64
- temp_user = 'flattendb_user'
65
- temp_pass = 'flattendb_pass'
58
+ is_root = mysql_user == 'root'
59
+
60
+ temp_db = ENV['FLATTEN_DB'] || 'flattendb_temp'
61
+ temp_db << '_%d_%d' % [Time.now, $$] if is_root
62
+
63
+ temp_user = ENV['FLATTEN_USER'] || 'flattendb_user'
64
+ temp_pass = ENV['FLATTEN_PASS'] || 'flattendb_pass'
66
65
 
67
- mysql_args = "--one-database -u#{temp_user} -p#{temp_pass} #{temp_db} < #{$infile}"
66
+ input = $infile =~ /\.gz\z/i ? "<(zcat #{$infile})" : "< #{$infile}"
67
+ mysql_args = "--one-database -u#{temp_user} -p#{temp_pass} #{temp_db} #{input}"
68
68
  dump_args = "--xml -u#{temp_user} -p#{temp_pass} #{temp_db} > #{$dump_file}"
69
69
 
70
70
  begin
71
71
  mysql = Mysql.real_connect('localhost', mysql_user, mysql_pass)
72
72
 
73
73
  mysql.query("CREATE DATABASE #{temp_db}")
74
- mysql.query("GRANT ALL ON #{temp_db}.* TO '#{temp_user}'@'localhost' IDENTIFIED BY '#{temp_pass}'")
74
+ mysql.query("GRANT ALL ON #{temp_db}.* TO '#{temp_user}'@'localhost' IDENTIFIED BY '#{temp_pass}'") if is_root
75
75
 
76
76
  system("#{mysql_cmd} #{mysql_args} && #{dump_cmd} #{dump_args}")
77
77
  rescue Mysql::Error => err
78
78
  abort "ERROR #{err.errno} (#{err.sqlstate}): #{err.error}"
79
79
  ensure
80
80
  if mysql
81
- mysql.query("REVOKE ALL ON #{temp_db}.* FROM '#{temp_user}'@'localhost'") \
82
- if mysql_user == 'root'
83
-
81
+ mysql.query("REVOKE ALL ON #{temp_db}.* FROM '#{temp_user}'@'localhost'") if is_root
84
82
  mysql.query("DROP DATABASE IF EXISTS #{temp_db}")
83
+
85
84
  mysql.close
86
85
  end
87
86
  end
@@ -89,3 +88,5 @@ else
89
88
  $infile = $dump_file
90
89
  end
91
90
  end
91
+
92
+ # vim:ft=ruby
@@ -106,7 +106,7 @@ module FlattenDB
106
106
  def flatten!(*args)
107
107
  raise NotImplementedError, 'must be defined by sub-class'
108
108
  end
109
-
109
+
110
110
  def to_xml(*args)
111
111
  raise NotImplementedError, 'must be defined by sub-class'
112
112
  end
@@ -3,9 +3,9 @@
3
3
  # #
4
4
  # A component of flattendb, the relational database flattener. #
5
5
  # #
6
- # Copyright (C) 2007 University of Cologne, #
7
- # Albertus-Magnus-Platz, #
8
- # 50932 Cologne, Germany #
6
+ # Copyright (C) 2007-2010 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50932 Cologne, Germany #
9
9
  # #
10
10
  # Authors: #
11
11
  # Jens Wille <jens.wille@uni-koeln.de> #
@@ -32,7 +32,7 @@ module FlattenDB
32
32
 
33
33
  MAJOR = 0
34
34
  MINOR = 0
35
- TINY = 4
35
+ TINY = 5
36
36
 
37
37
  class << self
38
38
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flattendb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-19 00:00:00 +01:00
12
+ date: 2010-02-02 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,16 +84,18 @@ files:
84
84
  - example/mysql-sample.sql
85
85
  has_rdoc: true
86
86
  homepage: http://prometheus.rubyforge.org/flattendb
87
+ licenses: []
88
+
87
89
  post_install_message:
88
90
  rdoc_options:
89
- - --line-numbers
90
- - --inline-source
91
+ - --charset
92
+ - UTF-8
91
93
  - --title
92
94
  - flattendb Application documentation
93
95
  - --main
94
96
  - README
95
- - --charset
96
- - UTF-8
97
+ - --line-numbers
98
+ - --inline-source
97
99
  - --all
98
100
  require_paths:
99
101
  - lib
@@ -112,9 +114,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
114
  requirements: []
113
115
 
114
116
  rubyforge_project: prometheus
115
- rubygems_version: 1.3.1
117
+ rubygems_version: 1.3.5
116
118
  signing_key:
117
- specification_version: 2
119
+ specification_version: 3
118
120
  summary: Flatten relational databases.
119
121
  test_files: []
120
122