Git Product home page Git Product logo

Comments (6)

alassek avatar alassek commented on August 29, 2024

What if I changed create_enum to do IF NOT EXISTS? Would that be sufficient?

from activerecord-pg_enum.

michaelherold avatar michaelherold commented on August 29, 2024

Yeah, I think that would work. I doubt you'd ever have colliding names in a single app.

Once I finish up what I'm currently working on at work, I'll have an environment for you to play with.

from activerecord-pg_enum.

alassek avatar alassek commented on August 29, 2024

It turns out that CREATE TYPE doesn't support IF NOT EXISTS so this is a bit more complicated. Probably going to have to use a DO block.

from activerecord-pg_enum.

stratigos avatar stratigos commented on August 29, 2024

@alassek thanks for this really handy gem! Im really enjoying using it in production.

I frequently reset my localdev databases, and run into this issue as well. In the meantime, I just wrote my own .sql file to destroy my custom enum types when I db:reset or db:setup.

As for IF NOT EXISTS :

It turns out that CREATE TYPE doesn't support IF NOT EXISTS so this is a bit more complicated. Probably going to have to use a DO block.

Im not sure if you meant a Ruby block or a SQL DO, but there are a few solutions for wrapping the CREATE TYPE in some other statement that first performs a check for the custom type. This answer from stackoverflow looks like a good candidate:

DO $$
BEGIN
    IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'my_type') THEN
        CREATE TYPE my_type AS
        (
            -- add fields...
        );
    END IF;
END$$;

If I had more time Id contribute towards a PR! Perhaps in a few weekends from now.

from activerecord-pg_enum.

alassek avatar alassek commented on August 29, 2024

@stratigos yes, that is basically what I had in mind... but I think there's another wrinkle to this. I don't want to blithely wipe out preexisting enums in a production environment, so I think this also needs to tap into the functionality added by rails/rails#22967

So in development, create_enum will automatically drop an existing enum and redefine it. But in production, you will still get the error. I think that's how I want this to work.

from activerecord-pg_enum.

jasonfb avatar jasonfb commented on August 29, 2024

**2021-10-13 - RESOLVED -JFB **

I seem to have this problem here with this on the Heroku Pipeline
verso-commerce ยท Pipeline | Heroku 2021-10-13 09-26-37

the pipeline documentation is here https://devcenter.heroku.com/articles/release-phase (it's a bit tricky if you've never seen it before)

my release-tasks.sh file looks like:

## Step to execute
bundle exec rails db:migrate

# check for a good exit
if [ $? -ne 0 ]
then
  puts "*** RELEASE COMMAND FAILED"
  # something went wrong; convey that and exit
  exit 1
fi

(I think this is standard-- the docs say that the db:migrate should be here)

But for some reason this then causes PG::DuplicateObject: ERROR: type "bill_strategies" already exists

My app.json file -- were Heroku tells you to define certain formation settings -- looks like so:

{
  "scripts":  {
    "postdeploy": "bundle exec rails data:migrate"
  },
  "addons": [
    "heroku-postgresql:standard-0"
  ],
  "environments": {
    "test": {
      "formation": {
        "test": {
          "quantity": 1,
          "size": "standard-2x"
        }
      }
    },
    "review": {
      "addons": [
        "heroku-postgresql:hobby-dev"
      ]
    }
  }
}

Note that data_migrations is from the gem https://github.com/jasonfb/nonschema_migrations

from activerecord-pg_enum.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.