Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion docs/features/sharding/cross-shard.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Some statements, like `CREATE INDEX CONCURRENTLY`, cannot run inside transaction

```postgresql
DROP INDEX IF EXISTS user_id_idx;
CREATE INDEX CONCURRENTLY user_id_idx USING btree(user_id);
CREATE INDEX CONCURRENTLY user_id_idx ON users USING btree(user_id);
```

## Under the hood
Expand Down
6 changes: 5 additions & 1 deletion docs/features/sharding/schema_management/primary_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ CREATE TABLE users (
If you run this command through PgDog, this table will be created on all shards. Underneath, Postgres expands `BIGSERIAL` to the following code:

```postgresql
BIGINT NOT NULL DEFAULT nextval('users_id_seq'::regclass)
CREATE TABLE users (
id BIGINT UNIQUE NOT NULL DEFAULT nextval('users_id_seq'::regclass),
email VARCHAR NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
```

The `users_id_seq` is a sequence, automatically created by Postgres, that will be used to generate unique values for inserted rows that don't provide one for the `id` column.
Expand Down
4 changes: 2 additions & 2 deletions docs/features/sharding/supported-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ Postgres has 3 kinds of queries, each handled a little bit differently in a shar

```postgresql
-- Sharding key equals a single value
SELECT * FROM users WHERE user_id = $1
SELECT * FROM users WHERE user_id = $1;

-- Sharding keys IN tuple
SELECT * FROM users WHERE id IN ($1, $2, $3)
SELECT * FROM users WHERE id IN ($1, $2, $3);
```

Queries that don't match this pattern will currently be routed to all shards. We are continuously adding support for more complex patterns.
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
markdown-it-py
regex
pglast
21 changes: 20 additions & 1 deletion tests/test_code_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
import subprocess
from markdown_it import MarkdownIt
import sys
import pglast

from regex import sub
from regex.regex import Regex, RegexFlag
mdp = MarkdownIt()

pattern = re.compile(r'(?msi)^(?P<fence>[`~]{3,})[ \t]*toml\b[^\n]*\r?\n(?P<code>.*?)^(?P=fence)[ \t]*\r?$',)
pattern = re.compile(
r'(?msi)^(?P<fence>[`~]{3,})[^\n]*\r?\n(?P<code>.*?)^(?P=fence)[ \t]*\r?$'
)

replication = [
"CREATE_REPLICATION_SLOT",
"START_REPLICATION",
]

def verify(binary):
for file in glob.glob("docs/**/*.md",
Expand All @@ -27,6 +35,17 @@ def verify(binary):
pass
else:
check_file(binary, "pgdog", token.content)
elif token.type == "fence" and token.info == "postgresql":
try:
pglast.parser.parse_sql(token.content)
except Exception as e:
found = False
for cmd in replication:
if cmd in token.content:
found = True
if not found:
print(token.content)
raise e

def check_file(binary, kind, content):
tmp = f"/tmp/pgdog_config_test.toml"
Expand Down
Loading