Remove SQL code from Rails schema file
NickName:NoDisplayName Ask DateTime:2015-04-03T13:19:28

Remove SQL code from Rails schema file

So a while ago I was working with triggers and added a few to one of my tables for insert and update events and thus they went to my schema.rb but then I found a way not to use triggers and removed them from the dabatase console but their sql code obviously hadn't been deleted from the schema file, so now I have something like that in it:

  execute(<<-TRIGGERSQL)
CREATE OR REPLACE FUNCTION public.arguments_vector_update()
 RETURNS trigger
 LANGUAGE plpgsql
AS $function$
BEGIN
    IF TG_OP = 'INSERT' THEN
        new.tsv_body = to_tsvector('pg_catalog.simple', COALESCE(NEW.text, ''));
    END IF;
    IF TG_OP = 'UPDATE' THEN
        IF NEW.text <> OLD.text THEN
            new.tsv_body = to_tsvector('pg_catalog.simple', COALESCE(NEW.text, ''));
        END IF;
    END IF;
    RETURN NEW;
END
$function$
  TRIGGERSQL

and I think I've deleted the migration file too -_-

I could probably add a new migration with the code to remove the trigers but it'd make the schema file even messier, so I wonder if there is another way to remove this code from the schema file ?

I am using PSQL, if it's important.

Copyright Notice:Content Author:「NoDisplayName」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29426621/remove-sql-code-from-rails-schema-file

More about “Remove SQL code from Rails schema file” related questions

Remove SQL code from Rails schema file

So a while ago I was working with triggers and added a few to one of my tables for insert and update events and thus they went to my schema.rb but then I found a way not to use triggers and removed...

Show Detail

Rails postgres structure.sql remove schema name

I've pulled down a Rails repo (# ruby '2.5.0', gem 'rails', '~> 5.1', gem 'pg', '~>1.0', &amp; psql 9.6.8) When running rake db:structure:dump the structure.sql is modified and the sche

Show Detail

Why does rails generate a schema.rb file even with schema format set to sql

I am running Rails 6.1.6 on ruby -v 2.7.1. I set this in my application.rb file config.active_record.schema_format = :sql I tried to run my migrations but schema.rb gets generated even as the exis...

Show Detail

Schema file ruby on rails

I've dropped my table successfully from the database from the console, using ActiveRecord::Migration.drop_table(:foo), But for some reason the table data still shows in the schema file. I would...

Show Detail

Remove `information_schema` from SQL dump

I am attempting to import a 40GB SQL backup on one of my servers and the software I used to automate the backups apparently included the "information_schema". Are there any tools/scripts/etc. that ...

Show Detail

Generate Rails migrations from a schema

I am creating a new Rails application which will work with an existing schema. I have been given the schema SQL but I want to create Rails migrations to populate the database in development. The sc...

Show Detail

Keep both structure.sql and schema.rb up to date in rails

I'm using a postgres feature that rails schema.rb file doesn't support so I've set config.active_record.schema_format = :sql to ensure that all aspects of my database schema are recorded. However...

Show Detail

Ruby On Rails ActiveRecord SQL view into schema

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql. The problem with this is that the view is not entered into the sche...

Show Detail

Remove all tables from schema except specific ones in SQL?

I have a SQL database and I would like to remove almost all tables related to a specific schema except a couple of them. Therefore I think I would need to edit the following sql query (which remove...

Show Detail

How to configure schema cache for rails 5 app?

So, I'm currently using Rails 5 and a mysql db on a project. I'm trying to use the ActiveRecord Schema Cache to eager load tables on my rails application without the need to query show full fields....

Show Detail