Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump default version; add upgrade script #72

Merged
merged 1 commit into from Mar 3, 2015

Conversation

jasonmp85
Copy link
Collaborator

Adding a new UDF means adding an upgrade script to augment existing installations of pg_shard.

fixes #69

@coveralls
Copy link

Coverage Status

Coverage remained the same at 93.2% when pulling 78ffe34 on feature-upgrade_script-#69 into 9838e1f on develop.

@@ -25,7 +25,7 @@ else
endif

EXTENSION = pg_shard
DATA = pg_shard--1.0.sql
DATA = pg_shard--1.1.sql pg_shard--1.0--1.1.sql
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how does this work? Will both files be executed on a CREATE EXTENSION command?

As I understand, and ALTER EXTENSION UPDATE on a 1.0 installation will add the new UDF.

Should we be moving the UDF to the 1.1 file, and keeping the above line as pg_shard--1.1.sql only? If I run a CREATE EXTENSION, shouldn't I expect the 1.1 file to include everything?
I'm not sure, so I'm just asking.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how does this work? Will both files be executed on a CREATE EXTENSION command?

No, the extension will come with exactly one version: 1.1. If you want 1.0 you'd download that version instead.

So for installing from scratch, the 1.1 script is used. For upgrading from 1.0, PostgreSQL will route a path from 1.0 to 1.1. Here it's trivial (a single file), so it'll execute that to perform the upgrade.

Should we be moving the UDF to the 1.1 file, and keeping the above line as pg_shard--1.1.sql only?

The UDF is already in the 1.1 file. We checked it into 1.0, but this Pull Request renames the file to 1.1. The 1.1 standalone file should include everything (double check for me).

If I run a CREATE EXTENSION, shouldn't I expect the 1.1 file to include everything?

It does. Don't think about the code in develop's history. Think about the history of releases. We released a 1.0 file in December. That's the only public install file so far. So for a 1.1 release we need two things:

  • A 1.1 install file, to install 1.1 from scratch
  • A 1.0-to-1.1 upgrade file, containing the delta between 1.0 and 1.1

This change renames the "main" install file to 1.1, satisfying the first requirement above and adds the upgrade script, satisfying the second.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UDF is already in the 1.1 file. We checked it into 1.0, but this Pull Request renames the file to 1.1. The 1.1 standalone file should include everything (double check for me).

Ah, ok. That part I didn't realize. For some reason, I thought the UDF was only in the 1.0-1.1.sql file. The rest of it makes sense then. I checked, and the 1.1 sql file looks good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last question then. The create-extension command also supports a version. If I specify create-extension version 1.0, would that work? (And create 1.0 without the UDF?)

After checking on that, and assuming we've tested 1.0-1.1 upgrade and a 1.1 fresh install, you're good to :shipit:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way to install version 1.0 would be to download 1.0 and use that. The state of affairs for our extensions seems to be:

  • The latest download contains a script to install that latest version
  • It also contains upgrade scripts from earlier versions

@jasonmp85
Copy link
Collaborator Author

As a sanity check, I looked over at cstore, which looks exactly like pg_shard will after this Pull Request.

Adding a new UDF means adding an upgrade script to augment existing
installations of pg_shard.
@jasonmp85
Copy link
Collaborator Author

Testing (not currently automated in any fashion):

  • Checked out tag v1.0.2 and ran make uninstall; make install. This places the control and 1.0 SQL file in my PostgreSQL extension area
  • Checked out this branch and ran make uninstall; make install. This replaces the control file with one defining 1.1 as the default version and adds the 1.1 upgrade (and install) script. This does not remove the 1.0 install script added by the first step
  • Modified the init.sql in our tests to first install 1.0 and then upgrade to the latest known version
  • Ran tests and verified they passed

Here is the SQL for the upgrade:

CREATE EXTENSION pg_shard VERSION '1.0';
ALTER EXTENSION pg_shard UPDATE;
# \dx
#                                List of installed extensions
#    Name   | Version |   Schema   |                       Description                       
# ----------+---------+------------+---------------------------------------------------------
#  pg_shard | 1.1     | public     | extension for sharding across remote PostgreSQL servers
#  plpgsql  | 1.0     | pg_catalog | PL/pgSQL procedural language
# (2 rows)

@jasonmp85
Copy link
Collaborator Author

So yeah, the two caveats are:

  • Future versions don't remove the "main" install script from previous versions
  • Our CI system (Travis) isn't currently testing upgrade paths (these could become numerous as time goes on anyhow, so we'll have to see how much support we need for previous versions before we go down the road of automating this).

But this patch works, works with an upgrade from 1.0, and matches what we're doing in cstore.

jasonmp85 added a commit that referenced this pull request Mar 3, 2015
@jasonmp85 jasonmp85 merged commit 7b2cda7 into develop Mar 3, 2015
@jasonmp85 jasonmp85 deleted the feature-upgrade_script-#69 branch March 3, 2015 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add v1.1 upgrade script
3 participants