Module: DataMapper::Migrations::OracleAdapter::SQL
- Included in:
- DataMapper::Migrations::OracleAdapter
- Defined in:
- lib/dm-migrations/adapters/dm-oracle-adapter.rb
Overview
:nodoc:
Instance Method Summary collapse
- #create_sequence_statements(model) ⇒ Object private
- #delete_table_statement(model) ⇒ Object private
- #drop_sequence_statement(model) ⇒ Object private
- #reset_sequence_statement(model) ⇒ Object private
- #schema_name ⇒ Object private
- #truncate_table_statement(model) ⇒ Object private
Instance Method Details
#create_sequence_statements(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 163 def create_sequence_statements(model) name = self.name table_name = model.storage_name(name) serial = model.serial(name) statements = [] if sequence_name = model_sequence_name(model) sequence_name = quote_name(sequence_name) column_name = quote_name(serial.field) statements << <<-SQL.compress_lines CREATE SEQUENCE #{sequence_name} NOCACHE SQL # create trigger only if custom sequence name was not specified unless serial.[:sequence] statements << <<-SQL.compress_lines CREATE OR REPLACE TRIGGER #{quote_name(default_trigger_name(table_name))} BEFORE INSERT ON #{quote_name(table_name)} FOR EACH ROW BEGIN IF inserting THEN IF :new.#{column_name} IS NULL THEN SELECT #{sequence_name}.NEXTVAL INTO :new.#{column_name} FROM dual; END IF; END IF; END; SQL end end statements end |
#delete_table_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
231 232 233 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 231 def delete_table_statement(model) "DELETE FROM #{quote_name(model.storage_name(name))}" end |
#drop_sequence_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
197 198 199 200 201 202 203 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 197 def drop_sequence_statement(model) if sequence_name = model_sequence_name(model) "DROP SEQUENCE #{quote_name(sequence_name)}" else nil end end |
#reset_sequence_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 206 def reset_sequence_statement(model) if sequence_name = model_sequence_name(model) sequence_name = quote_name(sequence_name) <<-SQL.compress_lines DECLARE cval INTEGER; BEGIN SELECT #{sequence_name}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{sequence_name} INCREMENT BY -' || cval || ' MINVALUE 0'; SELECT #{sequence_name}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{sequence_name} INCREMENT BY 1'; END; SQL else nil end end |
#schema_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
158 159 160 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 158 def schema_name @schema_name ||= select("SELECT SYS_CONTEXT('userenv','current_schema') FROM dual").first.freeze end |
#truncate_table_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
226 227 228 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 226 def truncate_table_statement(model) "TRUNCATE TABLE #{quote_name(model.storage_name(name))}" end |