I'm trying to get the SQL script generated from an alembic revision, but when I run:
alembic upgrade head --sql
It outputs the SQL of all revisions, and because there's a breaking revision in the middle (I haven't figured out why yet), I can't get the script from that point on. Moreover, I only want the SQL script of the last revision.
Is there a parameter to get that?
After some time trying to figure it out, and reading the docs, you can obtain the SQL of a single or multiple specific revisions by specifying start:end in the command line:
alembic upgrade <previous>:<current> --sql
It will even output the update to the alembic_version table.
The same works with downgrade:
alembic downgrade <current>:<previous> --sql
alembic upgrade <revision_name> --sql
Found this question when I was trying to get the sql script downgrade to the end.
(env)# alembic downgrade -1 --sql
ERROR:alembic.util.messaging:downgrade with --sql requires <fromrev>:<torev>
FAILED: downgrade with --sql requires <fromrev>:<torev>
The case is quite rare. Maybe someone will be useful.
If you need to get a SQL and only 1 revision, then you can do this:
alembic downgrade 6a68657325e7:-1 --sql
Related
I am trying to push my SQLAlchemy-models to create Tables in my heroku-postgres-database. I use this command:
heroku run alembic upgrade head
It starts to Run as expected. But after a while I just get error,
Bash: alembic: command not found.
How to resolve it?
I had the same problem and solved it, not sure it will work for everyone. I noticed that in my requirements.txt file, I did not have the alembic package listed. So alembic was not installed loading the files on Heroku! I tried using heroku run pip install alembic, which installed the package successfully but still didn't solve the problem! I tried heroku run alembic --version, still the same.
The way I solved it is by deleting the local requirments.txt folder and generated it again using pip freeze > requirements.txt, this time alembic was there of course! After pushing my changes to heroku everything worked fine!
I think you are using quotes in the command. If so, remove the quotation marks
I installed curl on my machine today by running brew install curl, and it installed curl but also ended up updating a bunch of other packages, including my postgres (I'm using postgresql12)
I end up running any insert statement (which will insert a primary key automatically), and I get this error:
[58P01] ERROR: could not access file "$libdir/uuid-ossp": No such file or directory
When I run select * from pg_extension, I see that I have uuid-ossp installed as an extension, so I do not know why it is not able to find this.
I am using MacOS
This isn't an answer to my question because I went to a last resort, but I ended up just reinstalling postgres: https://bitadj.medium.com/completely-uninstall-and-reinstall-psql-on-osx-551390904b86
I would still like to hear other answers on the matter, as I would not recommend my answer unless absolutely necessary
I am wondering if there is a way to run Update-Database from the Package Manager Console with something similar to the Rails --dry-run flag, in order to see what will be run before doing it. My googling has led to no corresponding command for EF.
Is there one? Is there a hack to do essentially the same thing?
You could use Update-Database with a -Script flag to generate a SQL script instead of applying the migration. If you don't specify a source migration, it will use the current database state as the starting point, so you can use the file to verify what would have been executed on the database.
https://msdn.microsoft.com/en-us/data/jj591621.aspx#script
When I try running Unicorn after setting up postgres (works perfectly with Trinidad and Thin) I get the following error.
dyld: lazy symbol binding failed:
Symbol not found: _rb_thread_select
Referenced from:/Users/pls/.rvm/gems/ruby-2.2.0#coinino/extensions/x86_64-darwin-13/2.2.0/do_postgres-0.10.14/do_postgres/do_postgres.bundle
Expected in: flat namespace
Datamapper connects to the database normally inside a model.rb which then is required in app.rb.
What is wrong and how do I fix it?
Edit: Looks like this is a bug in Ruby 2.2.0.
A call used by old versions of the pg gem has been removed in Ruby 2.2. More recent versions of the gem no longer use this call; I know the latest version (0.18.1) doesn't, but I don't know when that change was made. You can update the pg gem by running the following command:
bundle update pg
As long as you're doing this, you may want to run just a plain bundle update to update all of your project's gems to the most recent versions—who knows what else might be incompatible with Ruby 2.2?
As always when updating dependencies, test that the update doesn't introduce any new bugs before you deploy the new version to production. I doubt pg will cause any problems, but other gems might.
It looks like this is a bug in Ruby 2.2.0. Going to Ruby 2.1.5 gets things going without trouble.
I have an application that deals with timezones, so naturally I want to be able to view the list of timezones in Postgresql.
I tried to view all available timezones with the following command:
SELECT * FROM pg_timezone_names;
Which prints the following error:
ERROR: timezone directory stack overflow
I even tried limiting the results and received the same error:
SELECT * FROM pg_timezone_names LIMIT 10;
At first I thought it might just be my IDE of choice having issues, but I tried to run the same sql query on the command line and received the same error. I can't, for the life of me, find an answer to this issue. Any information would be helpful. Thanks!
EDIT: I'm using Postgresql 9.3 on Gentoo. Self compiled version of postgresql-server.
Note: I can query the pg_timezone_abbrevs table just fine, just not pg_timezone_names.
According to this Postgres FAQ:
...
On platforms that receive regular software updates including new tzdata files, it may be more convenient to rely on the system's copy of the tzdata files. This is possible as a compile-time option. Most Linux distributions choose this approach for their pre-built versions of PostgreSQL.
...
The compile-time option referred to is the --with-system-tzdata, which is described about half-way down this page.
My guess is that this flag is set by the Portage distribution you're using, and that the tzdata is either missing or corrupted on your system. On Gentoo, the tzdata is distributed in the timezone-data package, which you can find here.
Try:
# emerge timezone-data
Then see if that fixes the problem.
This is an answer to my own question.
The following is at least true on the Gentoo distro of linux, but I assume can be present on others.
What causes the error mentioned in my post is a symlink loop by /usr/share/zoneinfo/posix
To solve this error you just have to delete that symlink, as follows:
rm /usr/share/zoneinfo/posix
Pretty easy fix. Be aware that any update to zoneinfo will cause this symlink to be recreated and thus requiring you to remove it again. I haven't had any issues with this link being removed, but I can't say the same for others. If anyone has a reason for NOT deleting this symlink, just post a comment stating so.
Had the exact same issue on Ubuntu 14.04 LTS with PostgreSQL 9.3.3 however my recursive symlink was with /usr/share/zoneinfo/localtime. Fixed by running:
$ sudo unlink /usr/share/zoneinfo/localtime