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 << " CREATE SEQUENCE \#{quote_name(sequence_name)} NOCACHE\n SQL\n\n # create trigger only if custom sequence name was not specified\n unless serial.options[:sequence]\n statements << <<-SQL.compress_lines\n CREATE OR REPLACE TRIGGER \#{quote_name(default_trigger_name(table_name))}\n BEFORE INSERT ON \#{quote_name(table_name)} FOR EACH ROW\n BEGIN\n IF inserting THEN\n IF :new.\#{quote_name(serial.field)} IS NULL THEN\n SELECT \#{quote_name(sequence_name)}.NEXTVAL INTO :new.\#{quote_name(serial.field)} FROM dual;\n END IF;\n END IF;\n END;\n SQL\n end\n end\n\n statements\nend\n".compress_lines |
#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) " DECLARE\n cval INTEGER;\n BEGIN\n SELECT \#{quote_name(sequence_name)}.NEXTVAL INTO cval FROM dual;\n EXECUTE IMMEDIATE 'ALTER SEQUENCE \#{quote_name(sequence_name)} INCREMENT BY -' || cval || ' MINVALUE 0';\n SELECT \#{quote_name(sequence_name)}.NEXTVAL INTO cval FROM dual;\n EXECUTE IMMEDIATE 'ALTER SEQUENCE \#{quote_name(sequence_name)} INCREMENT BY 1';\n END;\n SQL\n else\n nil\n end\nend\n".compress_lines |
#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 |