uuidify 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 380fb482f0d0a03a34f56eef56396fb22da0ea73
4
- data.tar.gz: 2430fe027e8b2ac8a1f240db26a61f3392fc027c
3
+ metadata.gz: ad1332e0ef93f7cd6cc689db3942250db14b5fd5
4
+ data.tar.gz: 3aa98ffc9153120ff02049e02761ab1bfb846965
5
5
  SHA512:
6
- metadata.gz: ded454c7bb0eb31f985d539fab2c3da9f99f65b0a2f7160967ff94f3bf92b9cd48608ad330842eae21ef1bcb501d9b2002a516c1f81bbdda905f5504b8400c22
7
- data.tar.gz: aa8e8008e167ed87af4f9f2473956f807ed93db11aa6184e2d484735e62ee27508639c1d2495d0d89e941f938c80600234a6fbfdc1e29fe65a11d16b95f67087
6
+ metadata.gz: 801f0d9e6535a1b895a3d1fc2253276fb427737acfee1fe238807768c5c4c1b2f3da0795ee217d56a90a108b76051330f5ecbd8839c15c09af273691e04c4fcb
7
+ data.tar.gz: 7e21d98183818adca0f05bf6157ee476486954e1326437c20f9e2f246baf34e7b84b7ac84e03bbcd215f458892b598722a2a3a74d47d0cb0126098a0c57cef34
@@ -1,12 +1,12 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.19 (Darwin)
2
+ Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABCgAGBQJSqHy3AAoJEP5F5V2hilTWmDIH/A4HikYutQEudAdnql3Os3s1
6
- 02RBQB5sa+iQ9smiBsXaGI1DohUp4a1T+WEQNynq7eZ1NFk65G+4Od3ay6t+uCpN
7
- FANqv9H8eO1mrccCEuxoF3sGUJdUZ5komsSS5nxo4sUumKZTIvx4zYvLRl6NAkQo
8
- OlaTa5jcQ3Y/noGNg53V6GqFkPHNDrTVnnxw9aFu0WhORwuaWCjoKoQMNU59BG5j
9
- cpHQmUo7qESGN0u2WBo6YrY4wpbIHJ5ZlJYR3OxHWsCjuV2i2p+DTyxzcAF15efG
10
- RgU4jkKbYVDmtkXAlhKxwCN2aTsiDOg6+feLczyeAbGDyUhrGXU4BsWL/Cdf16s=
11
- =QCJ8
5
+ iQEcBAABCgAGBQJTFflsAAoJEP5F5V2hilTWplAIAKgAOf+dkZttPSLKrlHvKE5Q
6
+ OCJ15E2vQtQ+pSHC3oqJOWZ7AXTJwgdPfNO76SareiVxcJTJow4S/t10RfFaxbtd
7
+ FcJg0v+3zUW+OsIugZo5ekoG5MgGMPk6ZozPZ+cY+3CFeTO1hOwEwC2JvJaxzoB7
8
+ 7l9WEVcxVQw7/wbbQZRdW+xzey5lyfECg4XQnnJAcLlScI4SrK56fux9czPrjlJu
9
+ 6/auajj5vGhpyjd6fZRQ92qFTOW4+UcBw2veXG54ONUrqKIfQyD7pWkYtVMfW7Ol
10
+ uX1wIHUlrlwuUz4j9ZEfREyUXzgMzoOMuwDul2mxUropS2QTpsRuqJ8v/1yyDQI=
11
+ =54FE
12
12
  -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -1,12 +1,12 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
- Version: GnuPG/MacGPG2 v2.0.19 (Darwin)
2
+ Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABCgAGBQJSqHy3AAoJEP5F5V2hilTWoOoH/AsWUntuV4JGJPOmnOpTGnQh
6
- ZU/ocGk6gbBqSPgXRcDfCkMS6xuiQ/v131PUyFD3So7FUIMaN4MyEJwKhfCfrDPk
7
- eFWRmHuy/N/wJhJwcZZzbhXEUEaTZ8nnw5DMSXG8iJlCDzST3UvMx0m2rQ7q1It0
8
- SuWFfNdrwnXgrY5lT2Mg908SjdcpeSbwtQsPTmBzGBIL4GXv9rl9x0h9AobkH4gs
9
- mDKDtAv1mXDv6aMMbblh8oekRKEoApH+BBvh6LCGm3LVseFpD+WccRLELzzo1FAI
10
- /ZUJGLCGJMbej+XW9RrawSIBdpuAKZNIyJzmfzEqr+cHIFsexRc24r5Ss0CwZpo=
11
- =8iBy
5
+ iQEcBAABCgAGBQJTFflsAAoJEP5F5V2hilTWwGcH/1Kv3WxzodvqlWOaQEaePvwa
6
+ flwInVvAtnps4ySTzdtORvUeMzsjgR7JESLpbOBvXBrv51HTatRwXlIgWxNymg1Y
7
+ JkTo+LvWG5n6hoR6vsd67q/yc2gmIHm69J70RlwzF8WsNKIHprj6GyeqWP71RRsN
8
+ CseIfcSyVoDjJ7c98tSgp8N+j395+i3uMfJ5WIMSrrfy9Lch0otWazn7oAKhEi5g
9
+ J3vbN73dm1NMZHTo4BrjlkaYWnOS06zfKV4r/9gi6hmNqlEixAGaqyzMzlgkrwop
10
+ 7cRN81fP6b1Ou6o3M0BpPJeTRBq/YNAmIQ2epyExhKrTWvGC6K7ncZvlT6Vpw64=
11
+ =x0Cc
12
12
  -----END PGP SIGNATURE-----
@@ -3,4 +3,25 @@ class Uuidify::Uuid < ActiveRecord::Base
3
3
  if Rails::VERSION::MAJOR == 3
4
4
  attr_accessible :model_name, :model_id, :model_uuid
5
5
  end
6
+
7
+ def self.uuid_storage_type
8
+ connection.adapter_name == "PostgreSQL" ? :string : :binary
9
+ end
10
+
11
+ def self.uuid_to_sql_string uuid
12
+ if uuid_storage_type == :string
13
+ uuid.to_s
14
+ else
15
+ uuid.raw
16
+ end
17
+ end
18
+
19
+ def self.uuid_from_sql_string string
20
+ if uuid_storage_type == :string
21
+ UUIDTools::UUID.parse(string)
22
+ else
23
+ UUIDTools::UUID.parse_raw(string)
24
+ end
25
+ end
26
+
6
27
  end
@@ -1,12 +1,21 @@
1
1
  class CreateUuidifyUuids < ActiveRecord::Migration
2
2
  def up
3
+ uuid_type = connection.adapter_name == "PostgreSQL" ? :string : :binary
4
+
3
5
  create_table :uuidify_uuids do |t|
4
6
  t.string :model_name
5
7
  t.integer :model_id
6
- # t.string :model_uuid, :limit => 36
8
+
9
+ if uuid_type == :string
10
+ t.string :model_uuid, :limit => 36
11
+ end
12
+
7
13
  end
8
-
9
- execute "ALTER TABLE uuidify_uuids ADD COLUMN model_uuid BINARY(16)"
14
+
15
+ if uuid_type == :binary
16
+ execute "ALTER TABLE uuidify_uuids ADD COLUMN model_uuid BINARY(16)"
17
+ end
18
+
10
19
  add_index :uuidify_uuids, [:model_name, :model_id], :unique => true
11
20
  add_index :uuidify_uuids, :model_uuid, :unique => true
12
21
  add_index :uuidify_uuids, [:model_uuid, :model_id], :unique => true
@@ -19,7 +19,9 @@ module Uuidify::UuidifyConcern
19
19
  module ClassMethods
20
20
  # .find_by_uuid. Used lookup so we know it's not rails magic.
21
21
  def lookup_uuid(uuid)
22
- uuid = Uuidify::Uuid.where(:model_uuid => uuid.raw, :model_name => self.to_s).first
22
+ uuid = Uuidify::Uuid.uuid_to_sql_string(uuid)
23
+
24
+ uuid = Uuidify::Uuid.where(:model_uuid => uuid, :model_name => self.to_s).first
23
25
  uuid ? find(uuid.model_id) : nil
24
26
  end
25
27
 
@@ -31,6 +33,8 @@ module Uuidify::UuidifyConcern
31
33
  end
32
34
  end
33
35
  end
36
+
37
+
34
38
  end
35
39
 
36
40
  # Return a UUID, creating it if needed.
@@ -43,18 +47,24 @@ module Uuidify::UuidifyConcern
43
47
  uuid = Uuidify::Uuid.where(:model_name => model_name, :model_id => model_id).first
44
48
 
45
49
  if uuid.nil?
46
- new_uuid = UUIDTools::UUID.timestamp_create.raw
50
+ new_uuid = UUIDTools::UUID.timestamp_create
51
+ new_uuid = Uuidify::Uuid.uuid_to_sql_string(new_uuid)
52
+
47
53
  uuid = Uuidify::Uuid.create(:model_name => model_name, :model_id => self.id, :model_uuid => new_uuid)
48
54
  uuid.save!
49
55
  end
50
56
 
51
- UUIDTools::UUID.parse_raw(uuid.model_uuid)
57
+ Uuidify::Uuid.uuid_from_sql_string(uuid.model_uuid)
52
58
  end
53
59
 
60
+
54
61
  # Assign a UUID that came from an external source.
55
62
  def uuid= new_uuid
56
63
  abort_if_unsaved!
57
- Uuidify::Uuid.where(:model_name => self.class.to_s, :model_id => self.id).first_or_create!.update_column(:model_uuid, new_uuid.raw)
64
+
65
+ uuid_value = Uuidify::Uuid.uuid_to_sql_string(new_uuid)
66
+
67
+ Uuidify::Uuid.where(:model_name => self.class.to_s, :model_id => self.id).first_or_create!.update_column(:model_uuid, uuid_value)
58
68
  end
59
69
 
60
70
  private
@@ -1,3 +1,3 @@
1
1
  module Uuidify
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Uuidify
2
- VERSION = "0.4.0.pre"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,14 +1,34 @@
1
+ # development:
2
+ # adapter: mysql2
3
+ # host: 127.0.0.1
4
+ # database: uuidify_dev
5
+ # username: root
6
+ # pool: 5
7
+ # timeout: 5000
8
+
9
+ # test:
10
+ # adapter: mysql2
11
+ # host: 127.0.0.1
12
+ # database: uuidify_test
13
+ # username: root
14
+ # pool: 5
15
+ # timeout: 5000
16
+
1
17
  development:
2
- adapter: mysql2
3
- database: guidify
4
- user: root
18
+ adapter: postgresql
19
+ host: 127.0.0.1
20
+ database: uuidify_dev
21
+ username: postgres
22
+ password: 0R3EhgbYBBJE4KMK
5
23
  pool: 5
6
24
  timeout: 5000
7
25
 
8
26
  test:
9
- adapter: mysql2
10
- database: guidify_test
11
- user: root
27
+ adapter: postgresql
28
+ host: 127.0.0.1
29
+ database: uuidify_test
30
+ username: postgres
31
+ password: 0R3EhgbYBBJE4KMK
12
32
  pool: 5
13
33
  timeout: 5000
14
34
 
@@ -0,0 +1,18 @@
1
+ development:
2
+ adapter: postgresql
3
+ host: 127.0.0.1
4
+ database: uuidify_dev
5
+ username: postgres
6
+ password: 0R3EhgbYBBJE4KMK
7
+ pool: 5
8
+ timeout: 5000
9
+
10
+ test:
11
+ adapter: postgresql
12
+ host: 127.0.0.1
13
+ database: uuidify_test
14
+ username: postgres
15
+ password: 0R3EhgbYBBJE4KMK
16
+ pool: 5
17
+ timeout: 5000
18
+
@@ -1,32 +1,210 @@
1
- CREATE TABLE `bars` (
2
- `id` int(11) NOT NULL AUTO_INCREMENT,
3
- `created_at` datetime NOT NULL,
4
- `updated_at` datetime NOT NULL,
5
- PRIMARY KEY (`id`)
6
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
7
-
8
- CREATE TABLE `foos` (
9
- `id` int(11) NOT NULL AUTO_INCREMENT,
10
- `created_at` datetime NOT NULL,
11
- `updated_at` datetime NOT NULL,
12
- PRIMARY KEY (`id`)
13
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
14
-
15
- CREATE TABLE `schema_migrations` (
16
- `version` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
17
- UNIQUE KEY `unique_schema_migrations` (`version`)
18
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
19
-
20
- CREATE TABLE `uuidify_uuids` (
21
- `id` int(11) NOT NULL AUTO_INCREMENT,
22
- `model_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
23
- `model_id` int(11) DEFAULT NULL,
24
- `model_uuid` binary(16) DEFAULT NULL,
25
- PRIMARY KEY (`id`),
26
- UNIQUE KEY `index_uuidify_uuids_on_model_name_and_model_id` (`model_name`,`model_id`),
27
- UNIQUE KEY `index_uuidify_uuids_on_model_uuid` (`model_uuid`),
28
- UNIQUE KEY `index_uuidify_uuids_on_model_uuid_and_model_id` (`model_uuid`,`model_id`)
29
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1
+ --
2
+ -- PostgreSQL database dump
3
+ --
4
+
5
+ SET statement_timeout = 0;
6
+ SET lock_timeout = 0;
7
+ SET client_encoding = 'UTF8';
8
+ SET standard_conforming_strings = on;
9
+ SET check_function_bodies = false;
10
+ SET client_min_messages = warning;
11
+
12
+ --
13
+ -- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
14
+ --
15
+
16
+ CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
17
+
18
+
19
+ --
20
+ -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
21
+ --
22
+
23
+ COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
24
+
25
+
26
+ SET search_path = public, pg_catalog;
27
+
28
+ SET default_tablespace = '';
29
+
30
+ SET default_with_oids = false;
31
+
32
+ --
33
+ -- Name: bars; Type: TABLE; Schema: public; Owner: -; Tablespace:
34
+ --
35
+
36
+ CREATE TABLE bars (
37
+ id integer NOT NULL,
38
+ created_at timestamp without time zone NOT NULL,
39
+ updated_at timestamp without time zone NOT NULL
40
+ );
41
+
42
+
43
+ --
44
+ -- Name: bars_id_seq; Type: SEQUENCE; Schema: public; Owner: -
45
+ --
46
+
47
+ CREATE SEQUENCE bars_id_seq
48
+ START WITH 1
49
+ INCREMENT BY 1
50
+ NO MINVALUE
51
+ NO MAXVALUE
52
+ CACHE 1;
53
+
54
+
55
+ --
56
+ -- Name: bars_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
57
+ --
58
+
59
+ ALTER SEQUENCE bars_id_seq OWNED BY bars.id;
60
+
61
+
62
+ --
63
+ -- Name: foos; Type: TABLE; Schema: public; Owner: -; Tablespace:
64
+ --
65
+
66
+ CREATE TABLE foos (
67
+ id integer NOT NULL,
68
+ created_at timestamp without time zone NOT NULL,
69
+ updated_at timestamp without time zone NOT NULL
70
+ );
71
+
72
+
73
+ --
74
+ -- Name: foos_id_seq; Type: SEQUENCE; Schema: public; Owner: -
75
+ --
76
+
77
+ CREATE SEQUENCE foos_id_seq
78
+ START WITH 1
79
+ INCREMENT BY 1
80
+ NO MINVALUE
81
+ NO MAXVALUE
82
+ CACHE 1;
83
+
84
+
85
+ --
86
+ -- Name: foos_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
87
+ --
88
+
89
+ ALTER SEQUENCE foos_id_seq OWNED BY foos.id;
90
+
91
+
92
+ --
93
+ -- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -; Tablespace:
94
+ --
95
+
96
+ CREATE TABLE schema_migrations (
97
+ version character varying(255) NOT NULL
98
+ );
99
+
100
+
101
+ --
102
+ -- Name: uuidify_uuids; Type: TABLE; Schema: public; Owner: -; Tablespace:
103
+ --
104
+
105
+ CREATE TABLE uuidify_uuids (
106
+ id integer NOT NULL,
107
+ model_name character varying(255),
108
+ model_id integer,
109
+ model_uuid character varying(36)
110
+ );
111
+
112
+
113
+ --
114
+ -- Name: uuidify_uuids_id_seq; Type: SEQUENCE; Schema: public; Owner: -
115
+ --
116
+
117
+ CREATE SEQUENCE uuidify_uuids_id_seq
118
+ START WITH 1
119
+ INCREMENT BY 1
120
+ NO MINVALUE
121
+ NO MAXVALUE
122
+ CACHE 1;
123
+
124
+
125
+ --
126
+ -- Name: uuidify_uuids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
127
+ --
128
+
129
+ ALTER SEQUENCE uuidify_uuids_id_seq OWNED BY uuidify_uuids.id;
130
+
131
+
132
+ --
133
+ -- Name: id; Type: DEFAULT; Schema: public; Owner: -
134
+ --
135
+
136
+ ALTER TABLE ONLY bars ALTER COLUMN id SET DEFAULT nextval('bars_id_seq'::regclass);
137
+
138
+
139
+ --
140
+ -- Name: id; Type: DEFAULT; Schema: public; Owner: -
141
+ --
142
+
143
+ ALTER TABLE ONLY foos ALTER COLUMN id SET DEFAULT nextval('foos_id_seq'::regclass);
144
+
145
+
146
+ --
147
+ -- Name: id; Type: DEFAULT; Schema: public; Owner: -
148
+ --
149
+
150
+ ALTER TABLE ONLY uuidify_uuids ALTER COLUMN id SET DEFAULT nextval('uuidify_uuids_id_seq'::regclass);
151
+
152
+
153
+ --
154
+ -- Name: bars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
155
+ --
156
+
157
+ ALTER TABLE ONLY bars
158
+ ADD CONSTRAINT bars_pkey PRIMARY KEY (id);
159
+
160
+
161
+ --
162
+ -- Name: foos_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
163
+ --
164
+
165
+ ALTER TABLE ONLY foos
166
+ ADD CONSTRAINT foos_pkey PRIMARY KEY (id);
167
+
168
+
169
+ --
170
+ -- Name: uuidify_uuids_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
171
+ --
172
+
173
+ ALTER TABLE ONLY uuidify_uuids
174
+ ADD CONSTRAINT uuidify_uuids_pkey PRIMARY KEY (id);
175
+
176
+
177
+ --
178
+ -- Name: index_uuidify_uuids_on_model_name_and_model_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
179
+ --
180
+
181
+ CREATE UNIQUE INDEX index_uuidify_uuids_on_model_name_and_model_id ON uuidify_uuids USING btree (model_name, model_id);
182
+
183
+
184
+ --
185
+ -- Name: index_uuidify_uuids_on_model_uuid; Type: INDEX; Schema: public; Owner: -; Tablespace:
186
+ --
187
+
188
+ CREATE UNIQUE INDEX index_uuidify_uuids_on_model_uuid ON uuidify_uuids USING btree (model_uuid);
189
+
190
+
191
+ --
192
+ -- Name: index_uuidify_uuids_on_model_uuid_and_model_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
193
+ --
194
+
195
+ CREATE UNIQUE INDEX index_uuidify_uuids_on_model_uuid_and_model_id ON uuidify_uuids USING btree (model_uuid, model_id);
196
+
197
+
198
+ --
199
+ -- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -; Tablespace:
200
+ --
201
+
202
+ CREATE UNIQUE INDEX unique_schema_migrations ON schema_migrations USING btree (version);
203
+
204
+
205
+ --
206
+ -- PostgreSQL database dump complete
207
+ --
30
208
 
31
209
  INSERT INTO schema_migrations (version) VALUES ('20130612135708');
32
210