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

feat: add release workflow #38

Merged
merged 4 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: release

on:
workflow_dispatch:
inputs:
semver:
description: The semver to use
required: true
default: patch
type: choice
options:
- patch
- minor
- major
pull_request:
types: [closed]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: nearform/optic-release-automation-action@v3
with:
github-token: ${{ secrets.github_token }}
washingtonsoares marked this conversation as resolved.
Show resolved Hide resolved
semver: ${{ github.event.inputs.semver }}
commit-message: "chore: release {version}"
build-command: |
npm run update-version
16 changes: 0 additions & 16 deletions HISTORY.md

This file was deleted.

23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

# Temporal Tables

![](https://github.com/nearform/temporal_tables/workflows/ci/badge.svg)

_Version: 0.4.0_

This is an attempt to rewrite the postgresql [temporal_tables](https://github.com/arkhipov/temporal_tables) extension in PL/pgSQL, without the need for external c extension.

The goal is to be able to use it on AWS RDS and other hosted solutions, where using custom extensions or c functions is not an option.
Expand All @@ -20,6 +17,7 @@ With time, added some new functionality diverging from the original implementati
- [Ignore updates with no actual changes](#ignore-unchanged-values)

<a name="usage"></a>

## Usage

Create a database and the versioning function:
Expand Down Expand Up @@ -98,17 +96,18 @@ SELECT * FROM subscriptions_history

Should return something similar to:


name | state | sys_period
----- | ------------- | -------------------------------------------------------------------
test1 | inserted | ["2017-08-01 16:09:45.542983+02","2017-08-01 16:09:54.984179+02")
test1 | updated | ["2017-08-01 16:09:54.984179+02","2017-08-01 16:10:08.880571+02")
test1 | updated twice | ["2017-08-01 16:10:08.880571+02","2017-08-01 16:10:17.33659+02")
| name | state | sys_period |
| ----- | ------------- | ----------------------------------------------------------------- |
| test1 | inserted | ["2017-08-01 16:09:45.542983+02","2017-08-01 16:09:54.984179+02") |
| test1 | updated | ["2017-08-01 16:09:54.984179+02","2017-08-01 16:10:08.880571+02") |
| test1 | updated twice | ["2017-08-01 16:10:08.880571+02","2017-08-01 16:10:17.33659+02") |

<a name="additional-features"></a>

## Additional features

<a name="ignore-unchanged-values"></a>

### Ignore updates without actual change

By default this extension creates a record in the history table for every update that occurs in the versioned table, regardless of any change actually happening.
Expand All @@ -128,6 +127,7 @@ FOR EACH ROW EXECUTE PROCEDURE versioning(
```

<a name="migrations"></a>

## Migrations

During the life of an application is may be necessary to change the schema of a table. In order for temporal_tables to continue to work properly the same migrations should be applied to the history table as well.
Expand All @@ -149,6 +149,7 @@ From that point on the old column in the history table will be ignored and will
If the column doesn't accept null values you'll need to modify it to allow for null values, otherwise temporal_tables won't be able to create new rows and all operations on the original table will fail

<a name="test"></a>

## Test

In order to run tests:
Expand All @@ -168,6 +169,7 @@ make run_test_nochecks
Obviously, this suite won't run the tests about the error reporting.

<a name="performance_tests"></a>

## Performance tests

For performance tests run:
Expand Down Expand Up @@ -195,10 +197,12 @@ This required the original extentions to be installed, but will automatically ad
On the test machine (my laptop) the complete version is 2x slower than the nochecks versions and 16x slower than the original version.

Two comments about those results:

- original c version makes some use of caching (i.e to share an execution plan), whilst this version doesn't. This is propably accounting for a good chunk of the performance difference. At the moment there's not plan of implementing such caching in this version.
- The trigger still executes in under 1ms and in production environments the the network latency should be more relevant than the trigger itself.

<a name="the-team"></a>

## The team

### Paolo Chiodi
Expand All @@ -208,6 +212,7 @@ Two comments about those results:
[https://twitter.com/paolochiodi](https://twitter.com/paolochiodi)

<a name="acknowledgements"></a>

## Acknowledgements

This project was kindly sponsored by [nearForm](http://nearform.com).
Expand Down
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "temporal_tables",
"version": "0.4.0",
"description": "![](https://github.com/nearform/temporal_tables/workflows/ci/badge.svg)",
washingtonsoares marked this conversation as resolved.
Show resolved Hide resolved
"repository": {
"type": "git",
"url": "git+https://github.com/nearform/temporal_tables.git"
},
"scripts": {
"update-version": "node ./scripts/update-version.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/nearform/temporal_tables/issues"
},
"homepage": "https://github.com/nearform/temporal_tables#readme"
}
24 changes: 24 additions & 0 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
var { readFileSync, writeFileSync } = require("fs");

console.log("UPDATING VERSION ...");

const packageJson = require("../package.json");
const newVersion = packageJson.version;
const files = ["versioning_function", "versioning_function_nochecks"];

files.forEach((fileName) => {
const data = readFileSync(__dirname + `/../${fileName}.sql`, {
encoding: "utf8",
});

const updated = data.replace(
/-- version \d+.\d+.\d+/g,
`-- version ${newVersion}`
);

writeFileSync(__dirname + `/../${fileName}.sql`, updated, {
encoding: "utf8",
});
});

console.log("VERSION UPDATED!");
3 changes: 2 additions & 1 deletion versioning_function.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- version 0.4.0

CREATE OR REPLACE FUNCTION versioning()
RETURNS TRIGGER AS $$
DECLARE
Expand All @@ -14,7 +16,6 @@ DECLARE
holder2 record;
pg_version integer;
BEGIN
-- version 0.4.0

IF TG_WHEN != 'BEFORE' OR TG_LEVEL != 'ROW' THEN
RAISE TRIGGER_PROTOCOL_VIOLATED USING
Expand Down
3 changes: 2 additions & 1 deletion versioning_function_nochecks.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- version 0.4.0

CREATE OR REPLACE FUNCTION versioning()
RETURNS TRIGGER AS $$
DECLARE
Expand All @@ -11,7 +13,6 @@ DECLARE
transaction_info txid_snapshot;
existing_range tstzrange;
BEGIN
-- version 0.4.0

sys_period := TG_ARGV[0];
history_table := TG_ARGV[1];
Expand Down