somebee (owner)

Revisions

gist: 218064 Download_button fork
public
Public Clone URL: git://gist.github.com/218064.git
Embed All Files: show embed
do.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# encoding: utf-8
 
require 'rubygems'
require 'dm-core'
 
DataMapper.setup(:default,
  :adapter => 'mysql',
  :host => 'localhost',
  :username => 'root',
  :database => 'dm_core_test',
  :encoding => 'UTF-8'
)
 
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, :debug)
 
class Company
  include DataMapper::Resource
 
  property :id, Serial
  property :name, String
  has n, :invoices, :child_key => [:owner_id]
end
 
class Invoice
  include DataMapper::Resource
  
  property :id, Serial
  property :nr, Integer
  belongs_to :owner, :model => "Company", :child_key => [:owner_id]
end
 
DataMapper.auto_migrate!
 
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000078) SET sql_auto_is_null = 0
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000075) SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.079298) DROP TABLE IF EXISTS `companies`
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.002240) DROP TABLE IF EXISTS `invoices`
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000273) SHOW TABLES LIKE 'companies'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000296) SHOW VARIABLES LIKE 'character_set_connection'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000249) SHOW VARIABLES LIKE 'collation_connection'
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.080663) CREATE TABLE `companies` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
# Sun, 25 Oct 2009 14:00:43 GMT ~ debug ~ (0.000250) SHOW TABLES LIKE 'invoices'
# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.173635) CREATE TABLE `invoices` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `nr` INTEGER, `owner_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci
# Sun, 25 Oct 2009 14:00:44 GMT ~ debug ~ (0.154411) CREATE INDEX `index_invoices_owner` ON `invoices` (`owner_id`)
# /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `execute_non_query': Field 'owner_id' doesn't have a default value (DataObjects::SQLError)
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:72:in `block in execute'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:283:in `with_connection'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:70:in `execute'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:119:in `block in create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `each'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/adapters/data_objects_adapter.rb:92:in `create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/repository.rb:124:in `create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:877:in `_create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:669:in `create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:299:in `block in create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `catch'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/extlib-0.9.14/lib/extlib/hook.rb:297:in `create_hook'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:553:in `save_self'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:927:in `_save'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/resource.rb:344:in `save'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:610:in `_create'
# from /usr/local/ruby-1.9.1-p243/lib/ruby/gems/1.9.1/gems/dm-core-0.10.2/lib/dm-core/model.rb:401:in `create'
# from domigrate.rb:52:in `<main>'
manual.sql #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
mysql> USE dm_core_test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> SET sql_auto_is_null = 0;
Query OK, 0 rows affected (0.00 sec)
 
mysql> SET SESSION sql_mode = 'ANSI,NO_BACKSLASH_ESCAPES,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL';
Query OK, 0 rows affected (0.00 sec)
 
mysql> DROP TABLE IF EXISTS `companies`;
Query OK, 0 rows affected (0.04 sec)
 
mysql> DROP TABLE IF EXISTS `invoices`;
Query OK, 0 rows affected (0.01 sec)
 
mysql> SHOW TABLES LIKE 'companies';
Empty set (0.00 sec)
 
mysql> SHOW VARIABLES LIKE 'character_set_connection';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| character_set_connection | utf8 |
+--------------------------+-------+
1 row in set (0.00 sec)
 
mysql> SHOW VARIABLES LIKE 'collation_connection';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
+----------------------+-----------------+
1 row in set (0.00 sec)
 
mysql> CREATE TABLE `companies` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(50), PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 0 rows affected (0.07 sec)
 
mysql> SHOW TABLES LIKE 'invoices';
Empty set (0.00 sec)
 
mysql> CREATE TABLE `invoices` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `nr` INTEGER, `owner_id` INT(10) UNSIGNED NOT NULL, PRIMARY KEY(`id`)) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 0 rows affected (0.16 sec)
 
mysql> CREATE INDEX `index_invoices_owner` ON `invoices` (`owner_id`);
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
 
mysql>