Skip to content

Commit

Permalink
Revert "Revert "Postgres testing complete""
Browse files Browse the repository at this point in the history
This reverts commit 525ad43.
  • Loading branch information
dwin committed Jun 8, 2018
1 parent 525ad43 commit 2e4e610
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 22 deletions.
19 changes: 19 additions & 0 deletions pgsql/certs/ca.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDBzCCAe+gAwIBAgIRAJRPMz8rSwMm70KuJaqPRJQwDQYJKoZIhvcNAQELBQAw
KzESMBAGA1UEChMJQ29ja3JvYWNoMRUwEwYDVQQDEwxDb2Nrcm9hY2ggQ0EwHhcN
MTgwNjA3MTY1ODM4WhcNMjgwNjE1MTY1ODM4WjArMRIwEAYDVQQKEwlDb2Nrcm9h
Y2gxFTATBgNVBAMTDENvY2tyb2FjaCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEP
ADCCAQoCggEBAPQIOO7JgqlS3wfkbBVwHl4WXrqlFXYpIYROHTvHECbKleykU3Ot
z08cscujqZ3fucBVwwnMT4xzXtNCUSyvnMqcT3mrqYVmS8/49nQ8PJa6WZkLXYiG
I4T7BNCE97FcsJl24qopnv0+t9GuUylvO89SFklcsrot7aoCoZ8VO2kWJvWxweIX
IBog9SShIpwsVH9nNt7mpbsEcBXbxF8nKY2iDj7RgcI08MSPdkxRP7aNmtfJ3vH0
IDmzc02Z3EwqzGLB8EJenjGW7lwndqfKHZqROyxKkyBRtJ4f+VLWnTygFBhHpWlU
wyuyrQ/SFxy5OE1geu0QiHqAppDsJnveZ/sCAwEAAaMmMCQwDgYDVR0PAQH/BAQD
AgLkMBIGA1UdEwEB/wQIMAYBAf8CAQEwDQYJKoZIhvcNAQELBQADggEBAIrjjyUq
3QQROb43JMlZqFy9NAmhygJAdcu0o82ktAmeQmwsW3MG6AA/bPx8t53lcd1ncvrz
RFQGno0Q0nx0bXHaI4PGg3gjY/PreDi8EWs5j9D9IZk21k8nvH+k0j6aKEvyAWjq
Tm65swjYz6SCn/FfwExJokFZ2jDAvYXeJR57+H7cpBdm5Aw1QpwlhdtOJgGERzuO
H+o15K4Io9dUWrqS8HIGxJ+KaROGcOuM9DlWOOWNNtI35pPMVZFMNPCilPMCKJDC
0xyk7bP03FEe+hlziqe3dQvnFFw19IzAeOyzm3nA3/cowtROTCF8MC/i5XZ4YC6A
sBOq+fCJQ3ArgKg=
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions pgsql/certs/ca.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA9Ag47smCqVLfB+RsFXAeXhZeuqUVdikhhE4dO8cQJsqV7KRT
c63PTxyxy6Opnd+5wFXDCcxPjHNe00JRLK+cypxPeauphWZLz/j2dDw8lrpZmQtd
iIYjhPsE0IT3sVywmXbiqime/T630a5TKW87z1IWSVyyui3tqgKhnxU7aRYm9bHB
4hcgGiD1JKEinCxUf2c23ualuwRwFdvEXycpjaIOPtGBwjTwxI92TFE/to2a18ne
8fQgObNzTZncTCrMYsHwQl6eMZbuXCd2p8odmpE7LEqTIFG0nh/5UtadPKAUGEel
aVTDK7KtD9IXHLk4TWB67RCIeoCmkOwme95n+wIDAQABAoIBAAKi5BqQSr0RjB9F
tHU21N0nWLajeevg3d/UCDTRHbeNkLkRvWUOh6LPKIyOpBJ0jEkrpAPDFUjrJica
HE5jR0pZDfK+jAJI7KC+i8sNq4nlUXp5yPTknhWdsJugFBzyZ2YBBsnX0UPjHZFC
VNupu/etZ1g7jCK+xEaF6METNaUY9sQZxK2HjQFkDyHzSeyRsKFrsHZEJmnUiaYa
N7a3AX9v8CJaDrGaiC3gZjeuArPVFtra4HJSct3KasC35uqzLHsQtu7N3e8apnPQ
reXgNf+PGyuKRHcBjetR6VmLDBTgARLQjUOKzNoD/4xCCekqYvTmrTHNw8aEouYc
Wm2hfEECgYEA9fZrQuqvnX/agMN86W7BW7R7f2CdFrw7J/XEKvWtyMXb/BLGz0zO
8hNiHF2TTEEb+3zKQyD0I3sybfMpQLYnTwakjIy+Iwo7Zsv9D045gjAkltdJBRYs
wXOC7KEa5oPyHrXbLiLXYoFvcDZhN+xtxmgYeCpOeiprEX+SylfC1IkCgYEA/f2i
x4lml/UCSbWZa9mrn3Eh/xpE+U62qvekrsUORdzzD+XTW80uY8mOOKNzU7JD0Iz+
ajUyLdUuYjsbaAYSP83xRvT54vAvk7BMfwN4EKbFU9PDXGds7oLmkfQe7EN++LRG
1UCuaQxOPjP8YaVW+KlkLfoYQ7mEb+qRkmJUv2MCgYEAr9RixUmEFXGKwDX/m9hj
Pa1+A4cLhW82UtCsVZGflEFti3vYx+S+o+sbXe+/FuoMmPGSnf52yM6PNG559RrC
awnyo88RNXdhE5GL7F8dWWYVIgfw2UQK5pgu5f4dfuCgOzgB4a9ijba99VfKk/He
X9GWfICx7T9Znv617xRh4RECgYEAhDHEzVHoQeLVpAOOrKGIP94kMaA8kf2z+VwX
LJeHjDkpkPavgTJTmMBI85Wu6rr3rM4VhLXXPh+cmqfk5clzKh5IHARZIxKb0KSL
y/fEP/Zs8epf3fI+sg0TcJe8mH+w0EUUMN4PaMFs39cy3qetkpKnf36Rrn4aPh26
UpQ3Q70CgYEAnV95sjztHyjMNL4B5nlXDcmt179v/9maDh2LLja3zpBDAo9m2nLS
dktxtD7ymFguWkBIrc0r7cjv76WpO2/hpJmgWp6Q5/xt5vcfSVETLpztfPt/jQxc
muxSVVGr5ROOxAJEddsT+CBg1d/7GsrZoOFmtP+I3SIdxpQ7Ylkah6M=
-----END RSA PRIVATE KEY-----
4 changes: 4 additions & 0 deletions pgsql/certs/certs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ./certs

These certificates are for testing purposes only. These are not
secrets as they are not to be used in production.
19 changes: 19 additions & 0 deletions pgsql/certs/client.root.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-----BEGIN CERTIFICATE-----
MIIDADCCAeigAwIBA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ions pgsql/certs/client.root.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEArs+f2BsRPGAOYXNIn9mecq4BG1B8KqCDvr0sfo/YnvaAwsxO
4X//lNXsy5V1pg8+cWbd06Et4Qzk0Yr2BooEjD2SjV+FUHU1gosHxYT4Gb+082ps
CTrHQlbXJpjZLcnOJMknht3MBzEXqoAH/fRGJq/RYIiifeIM9iLlXzA1y1dnrPfB
0wGKBTk0QZ+DJ4iWneF8g7Zr4aEU2+KLvsiNGL4xR2T/Fh1RtOkOBUyJj9iCaWUu
LLvaDtaXqQCVx0YWPmn3gF0nHpDwqLztYvhSf5qQrUkgm5YRqZ9ISPJ+u7FjocTy
nAwUESuDzv7y3u+U14Zvq4QrgtQrBsilozbRqwIDAQABAoIBAAYhLZ+sQ0x0qcxs
+GzyeoXW6B8HEXOFMVls1LSTYqsgRZ+O/m0VyeZ0Idt5oCh0fGIJk1mqWyt7AkL+
tmXATSyFtC/U253Ynkm3ikw4v2JXwIaQgr1IHFiNJvopfeQHIX1UuFgYSuEtrYDD
AIS9HgCZRaQ25ku3s3CmBJjz3c8FcLfnCU/AciLUtZDSlbKYY7mBWui/aXoJ0ViI
CeK0Rf2ITROa0TRYbzOHlUU3OCFnsxXUy5a6ywkEyAD2WxmZeM+hQVssC5P8/vEm
K/i8+DdILdgY8KxDISiQPiG4T+OtbAb1nlYxlBZBZ7B94m47CIxldEFCvQRQoRWS
VFBOwuECgYEA3yGujrRrlyMRkRclgys+05l258u85GIaV/Ng7idr+n9+VLHcOZIy
GhTqqbFqs4MZq1cCBNO8K4sVAKMXAhDydg5uBx4k1ffhoKOprLvFGxyA1TwaMi0N
97yGMjeBudGX7aE+ORpBbpPigy08jBW+fLKgjXMYYpGK3xqMiXfy2OMCgYEAyI/E
8U4R1uQQ3gm1NRqUXW5Zmg3w0KN54kzWAuI0nReLxPpAt1lnXmWIN62d9EgHpFM8
dWBPBoroBVa/5++++IRrOvmRzM1/+Y5rlIxb4gaX74wOF/Y9huknfazoPB1rtTxG
29bpXKbIc5wDlHKU0rF8bPJZtP7qrCaso1bQppkCgYEApLGiuzhWdZ7v120DRjcE
T4DlsB/Ek7oJgcNlV0OHwsSaBX+mcmQDURcBQjFu9YMdzkcReWijamxlGyxFzkOe
Ax+RfPV18OzfAAftNE8AJIu8WCfdmg2BUss3LhekS/h1MHOkjtdfVnQXbAVWvHtM
N5RNRzqd1BtjKlvZQZpkiEsCgYBvH/mnGfKYdlVCMW7NtaRvAC11RjQf5fQqhxgt
ENjGEb3HrkEdVdQIYYlQEEpsh1x0mAnvnyUqItzb2G0MPbI6UGR5kL5QE6zMwTSq
YfqnCbA1cgx9Clqc3aKb56nlZQfAq103gaRbSa3XIKJ7JeF/vAeM9druhi/Qor0U
441IQQKBgGgDPcmA/5vQUsnmRs9tRuB4ITFaOqap+OfZm2lY5MlzvbBdf8EvsONp
zLTtUO89+1YP00/W3YOHG3wAIEwM+HOCrTS9jr2sIcWYlxDcWA0j9EKiIQIsYvoB
UIgvm/iMGM5HjiENrDwSW7CdLJSYuARkzEUSjNCJaRzwQ5ci/xvB
-----END RSA PRIVATE KEY-----
20 changes: 20 additions & 0 deletions pgsql/certs/server.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-----BEGIN CERTIFICATE-----
MIIDMzCCAhugAwIBAgIQfSvwIKDbRW7QSuUDBqt5JDANBgkqhkiG9w0BAQsFADAr
MRIwEAYDVQQKEwlDb2Nrcm9hY2gxFTATBgNVBAMTDENvY2tyb2FjaCBDQTAeFw0x
ODA2MDcxNjU4NDlaFw0yMzA2MTIxNjU4NDlaMCMxEjAQBgNVBAoTCUNvY2tyb2Fj
aDENMAsGA1UEAxMEbm9kZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
ALiNRk4NcyNDe15RycMuofNxWmLKz1DAkfYyup2y5mj1wgLXTUqk/hiQle5cAEbk
nRCXkeMQc1pwh4uZfSH+ToBb7ES/PKTavNxHpoe6HHntAaDrMH8w7LSveycXmpDG
b0+/FXZeq4UYnYUuMXj/rtcjRVN3p0W1tN0vdw8TNyToKYfEyOs58Yo9e3YEBzKD
6CPWBFADAdjs8rtdB6mOEWQv+qyDMUWkI5ygMMxWGhKjfaiSVQSDYfoS7+S5Bkgv
GsjtFksjV3TIqwFmFQepQE6hWy0MQUpx1dgX4RqsqGTEYSzohwYYlfoCWtqUeJya
X7srWEtPaj+1kWqrl01Se6cCAwEAAaNbMFkwDgYDVR0PAQH/BAQDAgWgMB0GA1Ud
JQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAoBgNVHREEITAfgglsb2NhbGhvc3SC
EkRhcndpbnMtaU1hYy5sb2NhbDANBgkqhkiG9w0BAQsFAAOCAQEAuDg41ul/1S3S
nOgwPxJIpzmCYp89PnDOm0U/W1SP4MuFDsQ+yfZbrpRUpwhYzB1IWoPWD6nXPiTd
WMjzBP8uJ2LKsTcuFve0YCujq59O7FPGugxAxvMJe4StZXC0yIg6XAhk7iFXQKQU
MqF1R1RqmKyjkQZo0bMP8kpiwEwrwePexcauuxKzc2es8WBxuNKJxGVn3K4BpsZS
fdIFNOnWQ2TX8c0ck+dc22wFjRghTwX31Ujqoc2SeSvRdu6QqtBbhyHeUE/Y51S2
K4kuKGxQ0SCcfl+lRL4RuFJdxxXrKImrVI7+wnG5s6Qqws0gSLHy8S5OnN6PVstg
J4buR2pBnw==
-----END CERTIFICATE-----
27 changes: 27 additions & 0 deletions pgsql/certs/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAuI1GTg1zI0N7XlHJwy6h83FaYsrPUMCR9jK6nbLmaPXCAtdN
SqT+GJCV7lwARuSdEJeR4xBzWnCHi5l9If5OgFvsRL88pNq83Eemh7ocee0BoOsw
fzDstK97JxeakMZvT78Vdl6rhRidhS4xeP+u1yNFU3enRbW03S93DxM3JOgph8TI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hoVw3dgsFye1u+VbIttb8sDGmexI
xRDoHwNFtRgcboqoD9ja8WqrN2f5lXBUiGDqA5OCZsuBmbNgvQtqSnVflKM7Yt+C
pjobXucg0BNrAkOzQEYhnw2r8ySvn6FWHzIpHIuE2Lw1pLlFBtTrVhfXhf5YioUw
BKAq95UCgYEAmQ7dewi0oEiXhF+EVy7l1rPbvXyxJv8iT0mzW/P61gmo+PaA8HJy
mekUd0ukI741OLn58Td/uVZNlUEMKcialBrjrvFEdxAJgNiOezdgdIr12eXfngG1
9xvKzDVaNdSO/y2qWZ2Ud0WDo23xzgRv8L8JiIYOpr0BK7PLPzbg/9k=
-----END RSA PRIVATE KEY-----
3 changes: 0 additions & 3 deletions pgsql/db_setup.sh

This file was deleted.

23 changes: 23 additions & 0 deletions pgsql/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Overview

This is a Postgres compatible version of [WUID](https://github.com/edwingeng/wuid).

- WUID is a unique number generator, but it is not a UUID implementation.
- WUID is 10-135 times faster than UUID and 4600 times faster than generating unique numbers with Redis.
- WUID generates unique 64-bit integers in sequence. The high 24 bits are loaded from a data store. By now, Redis, MySQL, and MongoDB are supported.

# Install
``` bash
go get -u github.com/edwingeng/wuid/...
Expand All @@ -15,6 +21,13 @@ dep ensure -add github.com/edwingeng/wuid/mongo
dep ensure -add github.com/edwingeng/wuid/callback
```

**_CockroachDB_**

[CockroachDB](https://www.cockroachlabs.com) uses the same connection driver as PostgreSQL,
but this package has not been tested with CockroachDB yet; however support is planned. I
expected it will not work properly in its current form because CockroachDB ```serial``` data
type is not sequential.

# Usage Examples

### PostgreSQL
Expand Down Expand Up @@ -47,4 +60,14 @@ CREATE TABLE wuid
h serial NOT NULL UNIQUE,
x int NOT NULL PRIMARY KEY DEFAULT '0'
);
```

Test Postgres Docker setup
> This will setup Docker Postgres:Alpine container with TLS, run tests and tear down Docker container.
```bash
# Run from package ../wuid/pgsql directory
## Make executable:
chmod +x testdb.sh
## Run:
./testdb.sh
```
26 changes: 26 additions & 0 deletions pgsql/testdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

## This will setup Docker Postgres:Alpine container, run test and tear down Docker container.
## Make executable: $ chmod +x testdb.sh
## Run: $ ./testdb.sh
mkdir db

docker run --name wuid-postgres -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d -v $(pwd)/db:/var/lib/postgresql/data postgres:alpine -c 'ssl=on'

sleep 30s

docker stop wuid-postgres

sleep 1s

cp certs/server.crt db/server.crt && cp certs/server.key db/server.key
chmod 0600 db/server.crt && chmod 0600 db/server.key
docker restart wuid-postgres

sleep 3s

go test -cover -bench=.

docker kill wuid-postgres && docker rm wuid-postgres

rm -rf db
11 changes: 4 additions & 7 deletions pgsql/wuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type WUID struct {
w *internal.WUID
}

// DefaultTimeout for db connection is 15 seconds
const DefaultTimeout int = 15

// NewWUID creates a new WUID instance.
func NewWUID(tag string, logger Logger, opts ...Option) *WUID {
var opts2 []internal.Option
Expand Down Expand Up @@ -97,13 +100,7 @@ func (this *WUID) LoadH24FromPg(host, user, pass, dbName, table string) error {
}

// Create connection string
dsn := "postgres://"
dsn += user
if len(pass) > 0 {
dsn += ":" + pass
}
dsn += "@" + host
dsn += "/" + dbName
dsn := fmt.Sprintf("host=%s user=%s password='%s' dbname=%s connect_timeout=%v", host, user, pass, dbName, DefaultTimeout)

return this.loadH24FromPg(dsn, table)
}
Expand Down
Loading

0 comments on commit 2e4e610

Please sign in to comment.