Module: DataMapper::Migrations::OracleAdapter::SQL
- Included in:
- DataMapper::Migrations::OracleAdapter
- Defined in:
- lib/dm-core/migrations.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#create_sequence_statements(model) ⇒ Object
private
TODO: document.
-
#delete_table_statement(model) ⇒ Object
private
TODO: document.
-
#drop_sequence_statement(model) ⇒ Object
private
TODO: document.
-
#reset_sequence_statement(model) ⇒ Object
private
TODO: document.
-
#schema_name ⇒ Object
private
TODO: document.
-
#truncate_table_statement(model) ⇒ Object
private
TODO: document.
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.
TODO: document
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 |
# File 'lib/dm-core/migrations.rb', line 983 def create_sequence_statements(model) table_name = model.storage_name(name) serial = model.serial(name) statements = [] if sequence_name = model_sequence_name(model) statements << <<-SQL.compress_lines CREATE SEQUENCE #{quote_name(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.#{quote_name(serial.field)} IS NULL THEN SELECT #{quote_name(sequence_name)}.NEXTVAL INTO :new.#{quote_name(serial.field)} 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.
TODO: document
1049 1050 1051 |
# File 'lib/dm-core/migrations.rb', line 1049 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.
TODO: document
1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/dm-core/migrations.rb', line 1014 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.
TODO: document
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 |
# File 'lib/dm-core/migrations.rb', line 1024 def reset_sequence_statement(model) if sequence_name = model_sequence_name(model) <<-SQL.compress_lines DECLARE cval INTEGER; BEGIN SELECT #{quote_name(sequence_name)}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{quote_name(sequence_name)} INCREMENT BY -' || cval || ' MINVALUE 0'; SELECT #{quote_name(sequence_name)}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{quote_name(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.
TODO: document
977 978 979 |
# File 'lib/dm-core/migrations.rb', line 977 def schema_name @schema_name ||= query("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.
TODO: document
1043 1044 1045 |
# File 'lib/dm-core/migrations.rb', line 1043 def truncate_table_statement(model) "TRUNCATE TABLE #{quote_name(model.storage_name(name))}" end |