Skip to content

Latest commit

 

History

History
213 lines (163 loc) · 5.44 KB

README.md

File metadata and controls

213 lines (163 loc) · 5.44 KB

PG SEMVER

GitHub tag

Contributors GitHub last commit (branch) license GitHub issues GitHub closed issues GitHub pull requests GitHub closed pull requests

Version Data type (SEMVER) for postgresql.

It enables Version to be inserted into tables as data type (CREATE TABLE versions(version SEMVER);).

Supported operations:

  • =
  • <>
  • >
  • >=
  • <
  • <=
  • ~
  ~1.2.3 := >=1.2.3 <1.(2+1).0 := >=1.2.3 <1.3.0
  ~0.2.3 := >=0.2.3 <0.(2+1).0 := >=0.2.3 <0.3.0
  • !~
  • ^
  ^1.2.3 := >=1.2.3 <2.0.0
  ^0.2.3 := >=0.2.3 <0.3.0
  ^0.0.3 := >=0.0.0 <0.1.0
  • !^

Example

More examples are available in test/sql directory.

CREATE TABLE versions(version SEMVER);

INSERT INTO versions VALUES ('1.0.0'), ('0.0.0'), ('2.5.0-beta1'), ('2.0.0-rc1'), ('2.10.0-beta0'), 
                            ('20.2.0-alpha'), ('30.0.0'), ('3.0.0'), ('3.0.0-rc2'), ('3.0.0-rc0'),
                            ('3.0.0-beta2'), ('3.0.0-alpha0');

SELECT * FROM versions WHERE version = '1.0.0';
 version 
---------
 1.0.0
(1 row)

SELECT * FROM versions WHERE version > '2.9-beta1';
   version    
--------------
 2.10.0-beta0
 20.2.0-alpha
 30.0.0
 3.0.0
 3.0.0-rc2
 3.0.0-rc0
 3.0.0-beta2
 3.0.0-alpha0
(8 rows)

SELECT * FROM versions ORDER BY version DESC;
   version    
--------------
 30.0.0
 20.2.0-alpha
 3.0.0
 3.0.0-rc2
 3.0.0-rc0
 3.0.0-beta2
 3.0.0-alpha0
 2.10.0-beta0
 2.5.0-beta1
 2.0.0-rc1
 1.0.0
 0.0.0
(12 rows)

2 versions can also be compared without inserting into any table:

SELECT PG_SEMVER_CMP('1.0.0-alpha.1', '1.0.0-alpha.2');
 pg_semver_cmp 
---------------
            -1
(1 row)

SELECT PG_SEMVER_CMP('0.0.1', '0.0.1');
 pg_semver_cmp 
---------------
             0
(1 row)

SELECT PG_SEMVER_CMP('0.0.2', '0.0.1');
 pg_semver_cmp 
---------------
             1
(1 row)

Installing by compiling source code

Prerequisites

Ubuntu:

# add postgres repo
add-apt-repository 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# install postgres
apt-get -y update
apt-get -y install postgresql postgresql-contrib libpq-dev postgresql-server-dev-all

# install build requirements
apt-get -y install make build-essential

RHEL:

yum -y install openssl-devel

# add postgres repo
rpm -Uvh https://yum.postgresql.org/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

# install postgres
yum -y install postgresql10-server postgresql10-libs postgresql10-devel postgresql10-contrib

# initialize databasse
/usr/pgsql-10/bin/postgresql-10-setup initdb

Build

make
make install

If you encounter an error such as:

make: pg_config: Command not found

Be sure that you have pg_config installed and in your path. If you used a package management system such as RPM to install PostgreSQL, be sure that the -devel package is also installed. If necessary tell the build process where to find it. Edit Makefile, and change PG_CONFIG variable:

PG_CONFIG=/path/to/pg_config

followed by the

make
make install

pg_config is usually under /usr/pgsql-10/bin/pg_config on RHEL/CentOS/Fedora. Replace 10 with your major PostgreSQL version.

Alternatively the following will work too:

PATH="/usr/pgsql-10/bin:$PATH" make
sudo PATH="/usr/pgsql-10/bin:$PATH" make install
PATH="/usr/pgsql-10/bin:$PATH" make installcheck

Using the module

To enable this module, add '$libdir/pg_semver' to shared_preload_libraries in postgresql.conf, then restart the server.

Testing

Using vagrant:

vagrant up
vagrant provision --provision-with install

Contributing

Bug reports and pull requests are welcome on GitHub at pg_semver repository. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

  1. Fork it ( https://github.com/eendroroy/pg_semver/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Author

License

The project is available as open source under the terms of the MIT License.