# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           golang 1.0

go.setup            github.com/xataio/pgroll 0.10.0 v
go.offline_build    no
revision            0

homepage            https://xata.io/blog/pgroll-schema-migrations-postgres

description         Postgres zero-downtime migrations made easy

long_description    \
    ${name} is an open source command-line tool that offers safe and \
    reversible schema migrations for PostgreSQL by serving multiple schema \
    versions simultaneously. It takes care of the complex migration \
    operations to ensure that client applications continue working while the \
    database schema is being updated. This includes ensuring changes are \
    applied without locking the database, and that both old and new schema \
    versions work simultaneously \(even when breaking changes are being \
    made\!\). This removes risks related to schema migrations, and greatly \
    simplifies client application rollout, also allowing for instant rollbacks.

categories          databases
installs_libs       no
license             Apache-2
maintainers         {gmail.com:herby.gillot @herbygillot} \
                    openmaintainer

checksums           rmd160  bffcba723de9bbe4f3d269e40f6649ecad94feed \
                    sha256  a589431e37ad6dc16af8e8835d6c1094cd3c767abe11743cc1f2816f6a8a538e \
                    size    561453

github.livecheck.regex \
                    {([0-9.]+)}

build.pre_args-append \
    -ldflags=\"-X ${go.package}/cmd.Version=${version}\"

set comppath ${workpath}/completions

post-build {
    file mkdir ${comppath}

    foreach shell {bash fish zsh} {
        system -W ${worksrcpath} \
            "${worksrcpath}/${name} completion ${shell} > ${comppath}/${name}.${shell}"
    }
}

destroot {
    xinstall -m 0755 ${worksrcpath}/${name} ${destroot}${prefix}/bin/

    xinstall -d ${destroot}${prefix}/share/${name}
    copy ${worksrcpath}/examples ${destroot}${prefix}/share/${name}/

    # Shell completions
    set bash_comp_path ${destroot}${prefix}/share/bash-completion/completions
    xinstall -d ${bash_comp_path}
    copy ${comppath}/${name}.bash ${bash_comp_path}/${name}

    set fish_comp_path ${destroot}${prefix}/share/fish/vendor_completions.d
    xinstall -d ${fish_comp_path}
    copy ${comppath}/${name}.fish ${fish_comp_path}

    set zsh_comp_path ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${zsh_comp_path}
    copy ${comppath}/${name}.zsh ${zsh_comp_path}/_${name}
}
