chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
FROM postgres:16
|
||||
|
||||
ENV POSTGRES_PASSWORD=password
|
||||
ENV POSTGRES_USER=postgres
|
||||
|
||||
ENV GO_VERSION=1.23.3
|
||||
|
||||
# Install Go
|
||||
RUN apt-get update && \
|
||||
apt-get install -y wget sudo git build-essential libicu-dev && \
|
||||
wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
|
||||
tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \
|
||||
rm go${GO_VERSION}.linux-amd64.tar.gz
|
||||
|
||||
# Install bats
|
||||
RUN git clone https://github.com/bats-core/bats-core.git
|
||||
WORKDIR bats-core
|
||||
RUN ./install.sh $HOME
|
||||
ENV PATH="/root/bin/:${PATH}"
|
||||
|
||||
# Set Go environment variables
|
||||
ENV PATH="/usr/local/go/bin:${PATH}"
|
||||
|
||||
# Doltgres source
|
||||
WORKDIR /root/building
|
||||
COPY ./ ./doltgresql
|
||||
|
||||
# Get rid of the generated tests, since we aren't going to run them and they don't build without more work
|
||||
RUN rm -rf ./doltgresql/testing/generation/
|
||||
|
||||
# Build the parser
|
||||
WORKDIR /root/building/doltgresql/postgres/parser
|
||||
RUN bash ./build.sh
|
||||
|
||||
# Build the doltgres binary, which we will need for bats, and put it on PATH
|
||||
WORKDIR /root/building/doltgresql/cmd/doltgres
|
||||
RUN go build .
|
||||
RUN cp ./doltgres /root/bin
|
||||
|
||||
WORKDIR /root/building/doltgresql/
|
||||
|
||||
# This env var is required to run the bats replication tests
|
||||
ENV RUN_DOLTGRES_REPLICATION_TESTS=true
|
||||
# This should be set in the github env, but set it here for local testing as well
|
||||
ENV GITHUB_ACTION=true
|
||||
|
||||
# Run the test script, which starts postgres and then runs the Go script
|
||||
ENTRYPOINT ["testing/replication-test-entrypoint.sh"]
|
||||
|
||||
@@ -0,0 +1,260 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
# Tests that we can successfully load the french towns dataset into Doltgres
|
||||
# https://github.com/morenoh149/postgresDBSamples/blob/master/french-towns-communes-francaises/french-towns-communes-francaises.sql
|
||||
@test 'dataloading: tabular import, french towns dataset' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/french-towns-communes-francaises.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 26" ]] || false
|
||||
[[ "$output" =~ "COPY 100" ]] || false
|
||||
[[ "$output" =~ "COPY 36684" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
[[ ! "$output" =~ "is not yet supported" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "26" ]] || false
|
||||
run query_server -c "SELECT count(*) from Departments;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "100" ]] || false
|
||||
run query_server -c "SELECT count(*) from Towns;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "36684" ]] || false
|
||||
|
||||
# Spot check a row from each table
|
||||
run query_server -c "SELECT * from Regions where id=21;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "21 | 74 | 87085 | Limousin" ]] || false
|
||||
run query_server -c "SELECT * from Departments where id=42;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "42 | 41 | 41018 | 24 | Loir-et-Cher" ]] || false
|
||||
run query_server -c "SELECT * from Towns where id=420;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "420 | 001 | | Abbécourt | 02" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load data dump files with windows line endings.
|
||||
@test 'dataloading: tabular import, windows line endings' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/windows-line-endings.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 26" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "26" ]] || false
|
||||
|
||||
# Spot check a row
|
||||
run query_server -c "SELECT * from Regions where id=21;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "21 | 74 | 87085 | Limousin" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load tabular data dump files that contain a header
|
||||
@test 'dataloading: tabular import, with header' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/tab-load-with-header.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 01 | 97105 | Guadeloupe" ]] || false
|
||||
[[ "$output" =~ "2 | 02 | 97209 | Martinique" ]] || false
|
||||
[[ "$output" =~ "3 | 03 | 97302 | Guyane" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load tabular data dump files that contain quoted column names
|
||||
@test 'dataloading: tabular import, with quoted column names' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/tab-load-with-quoted-column-names.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * from Regions;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 01 | 97105 | Guadeloupe" ]] || false
|
||||
[[ "$output" =~ "2 | 02 | 97209 | Martinique" ]] || false
|
||||
[[ "$output" =~ "3 | 03 | 97302 | Guyane" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load tabular data dump files that do not explicitly manage the session's transaction.
|
||||
@test 'dataloading: tabular import, no explicit tx management' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/tab-load-with-no-tx-control.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * FROM test_info ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "4 | string for 4 | 1" ]] || false
|
||||
[[ "$output" =~ "5 | string for 5 | 0" ]] || false
|
||||
[[ "$output" =~ "6 | string for 6 | 0" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load tabular data dump files that specify a delimiter.
|
||||
@test "dataloading: tabular import, delimiter='|', no explicit tx management" {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/tab-load-with-delimiter-no-tx-control.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * FROM test_info ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "4 | string for 4 | 1" ]] || false
|
||||
[[ "$output" =~ "5 | string for 5 | 0" ]] || false
|
||||
[[ "$output" =~ "6 | string for 6 | 0" ]] || false
|
||||
}
|
||||
|
||||
# Tests loading in data via different CSV data files.
|
||||
@test 'dataloading: csv import' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/csv-load-basic-cases.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 9" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from tbl1;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "9" ]] || false
|
||||
|
||||
# Assert the data was loaded correctly
|
||||
run query_server -c "SELECT * from tbl1 order by pk;"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 17 ]
|
||||
[[ "$output" =~ "1 | green | " ]] || false
|
||||
[[ "$output" =~ "2 | blue | a +" ]] || false
|
||||
[[ "$output" =~ " | | q +" ]] || false
|
||||
[[ "$output" =~ " | | u +" ]] || false
|
||||
[[ "$output" =~ " | | a" ]] || false
|
||||
[[ "$output" =~ "3 | brown |" ]] || false
|
||||
[[ "$output" =~ "4 | NULL | NULL" ]] || false
|
||||
[[ "$output" =~ "5 | ? |" ]] || false
|
||||
[[ "$output" =~ "6 | foo +| baz" ]] || false
|
||||
# NOTE: \. has to be escaped as \\\\.
|
||||
[[ "$output" =~ " | \\\\. +|" ]] || false
|
||||
[[ "$output" =~ " | bar |" ]] || false
|
||||
[[ "$output" =~ "7 | | ' '" ]] || false
|
||||
[[ "$output" =~ "8 | |" ]] || false
|
||||
[[ "$output" =~ "9 | | ''" ]] || false
|
||||
|
||||
# Assert NULL values were properly identified
|
||||
run query_server -c "SELECT * from tbl1 where c2 is NULL;"
|
||||
[[ "$output" =~ " 1 | green | " ]] || false
|
||||
[[ "$output" =~ " 3 | brown | " ]] || false
|
||||
run query_server -c "SELECT * from tbl1 where c1 is NULL;"
|
||||
[ "${#lines[@]}" -eq 4 ]
|
||||
[[ "$output" =~ " 9 | | ''" ]] || false
|
||||
}
|
||||
|
||||
# Tests loading in CSV data that includes a header row.
|
||||
@test 'dataloading: csv import with header' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/csv-load-with-header.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 9" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from tbl1;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "9" ]] || false
|
||||
}
|
||||
|
||||
# Tests loading in data via a CSV data file that is large enough to be split across multiple chunks.
|
||||
@test 'dataloading: csv import across multiple chunks' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/csv-load-multi-chunk.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 100" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from tbl1;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "100" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load CSV data dump files that do not explicitly manage the session's transaction.
|
||||
@test 'dataloading: csv import, no explicit tx management' {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/csv-load-with-no-tx-control.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * FROM test_info ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "4 | string for 4 | 1" ]] || false
|
||||
[[ "$output" =~ "5 | string for 5 | 0" ]] || false
|
||||
[[ "$output" =~ "6 | string for 6 | 0" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load CSV data dump files that do not explicitly manage the session's transaction.
|
||||
@test "dataloading: csv import, delimiter='|', no explicit tx management" {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/psv-load-with-no-tx-control.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 3" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the inserted rows
|
||||
run query_server -c "SELECT * FROM test_info ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "4 | string for 4 | 1" ]] || false
|
||||
[[ "$output" =~ "5 | string for 5 | 0" ]] || false
|
||||
[[ "$output" =~ "6 | string for 6 | 0" ]] || false
|
||||
}
|
||||
|
||||
# Tests that we can load CSV data dump files using Postgres' legacy syntax
|
||||
@test "dataloading: csv import, legacy syntax" {
|
||||
# Import the data dump and assert the expected output
|
||||
run query_server -f $BATS_TEST_DIRNAME/dataloading/csv-load-with-legacy-syntax.sql
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "COPY 9" ]] || false
|
||||
[[ ! "$output" =~ "ERROR" ]] || false
|
||||
|
||||
# Check the row count of imported tables
|
||||
run query_server -c "SELECT count(*) from tbl1;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "9" ]] || false
|
||||
|
||||
# Spot check a row
|
||||
run query_server -c "SELECT * FROM tbl1 WHERE pk=3 and c2 IS NULL;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ " 3 | brown | " ]] || false
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE tbl1 (pk int primary key, c1 varchar(100), c2 varchar(250));
|
||||
|
||||
COPY tbl1 FROM STDIN (FORMAT CSV);
|
||||
1,green,
|
||||
2,"blue","a
|
||||
q
|
||||
u
|
||||
a"
|
||||
3,"brown",
|
||||
4,"NULL",NULL
|
||||
5,"?",""
|
||||
6,"foo
|
||||
\\.
|
||||
bar","baz"
|
||||
7, ,' '
|
||||
8," ",""
|
||||
9,,''
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,109 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE tbl1 (pk int primary key, c1 varchar(100), c2 varchar(250));
|
||||
|
||||
COPY tbl1 FROM STDIN (FORMAT CSV);
|
||||
0,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
1,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
2,foo,barbazbashbarbazbashbarbazbash
|
||||
3,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
4,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
5,foo,barbazbashbarbazbashbarbazbash
|
||||
6,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
7,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
8,foo,barbazbashbarbazbashbarbazbash
|
||||
9,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
10,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
11,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
12,foo,barbazbashbarbazbashbarbazbash
|
||||
13,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
14,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
15,foo,barbazbashbarbazbashbarbazbash
|
||||
16,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
17,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
18,foo,barbazbashbarbazbashbarbazbash
|
||||
19,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
20,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
21,foo,barbazbashbarbazbashbarbazbash
|
||||
22,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
23,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
24,foo,barbazbashbarbazbashbarbazbash
|
||||
25,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
26,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
27,foo,barbazbashbarbazbashbarbazbash
|
||||
28,foo,barbazbashbarbazbashbarbazbashbarbazbash
|
||||
29,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
30,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
31,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
32,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
33,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
34,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
35,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
36,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
37,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
38,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
39,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
40,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
41,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
42,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
43,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
44,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
45,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
46,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
47,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
48,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
49,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
50,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
51,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
52,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
53,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
54,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
55,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
56,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
57,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
58,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
59,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
60,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
61,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
62,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
63,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
64,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
65,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
66,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
67,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
68,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
69,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
70,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
71,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
72,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
73,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
74,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
75,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
76,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
77,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
78,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
79,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
80,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
81,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
82,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
83,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
84,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
85,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
86,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
87,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
88,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
89,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
90,foo,"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
|
||||
345678901234567"
|
||||
91,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
92,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
93,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
94,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
95,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
96,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
97,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
98,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
99,foo,barbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbashbarbazbash
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE tbl1 (pk int primary key, c1 varchar(100), c2 varchar(250));
|
||||
|
||||
COPY tbl1 FROM STDIN (FORMAT CSV, HEADER TRUE);
|
||||
pk,c1,c2
|
||||
1,green,
|
||||
2,"blue","a
|
||||
q
|
||||
u
|
||||
a"
|
||||
3,"brown",
|
||||
4,"NULL",NULL
|
||||
5,"?",""
|
||||
6,"foo
|
||||
\\.
|
||||
bar","baz"
|
||||
7, ,' '
|
||||
8," ",""
|
||||
9,,''
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,24 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE tbl1 (pk int primary key, c1 varchar(100), c2 varchar(250));
|
||||
|
||||
-- NOTE: This is legacy syntax, but still in use and still supported by PostgreSQL
|
||||
COPY tbl1 FROM STDIN CSV, HEADER;
|
||||
pk,c1,c2
|
||||
1,green,
|
||||
2,"blue","a
|
||||
q
|
||||
u
|
||||
a"
|
||||
3,"brown",
|
||||
4,"NULL",NULL
|
||||
5,"?",""
|
||||
6,"foo
|
||||
\\.
|
||||
bar","baz"
|
||||
7, ,' '
|
||||
8," ",""
|
||||
9,,''
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE test (pk int primary key);
|
||||
INSERT INTO test VALUES (0), (1);
|
||||
|
||||
CREATE TABLE test_info (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references test(pk));
|
||||
|
||||
COPY test_info FROM STDIN (FORMAT CSV, HEADER TRUE);
|
||||
id,info,test_pk
|
||||
4,string for 4,1
|
||||
5,string for 5,0
|
||||
6,string for 6,0
|
||||
\.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE test (pk int primary key);
|
||||
INSERT INTO test VALUES (0), (1);
|
||||
|
||||
CREATE TABLE test_info (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references test(pk));
|
||||
|
||||
COPY test_info FROM STDIN (FORMAT CSV, HEADER TRUE, DELIMITER '|');
|
||||
id|info|test_pk
|
||||
4|string for 4|1
|
||||
5|string for 5|0
|
||||
6|string for 6|0
|
||||
\.
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE test (pk int primary key);
|
||||
INSERT INTO test VALUES (0), (1);
|
||||
|
||||
CREATE TABLE test_info (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references test(pk));
|
||||
|
||||
COPY test_info FROM STDIN WITH (DELIMITER '|', HEADER);
|
||||
id|info|test_pk
|
||||
4|string for 4|1
|
||||
5|string for 5|0
|
||||
6|string for 6|0
|
||||
\.
|
||||
@@ -0,0 +1,17 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE Regions (
|
||||
id SERIAL UNIQUE NOT NULL,
|
||||
code VARCHAR(4) UNIQUE NOT NULL,
|
||||
capital VARCHAR(10) NOT NULL,
|
||||
name VARCHAR(255) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
COPY regions (id, code, capital, name) FROM stdin WITH (HEADER);
|
||||
id code capital name
|
||||
1 01 97105 Guadeloupe
|
||||
2 02 97209 Martinique
|
||||
3 03 97302 Guyane
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,11 @@
|
||||
CREATE TABLE test (pk int primary key);
|
||||
INSERT INTO test VALUES (0), (1);
|
||||
|
||||
CREATE TABLE test_info (id int, info varchar(255), test_pk int, primary key(id), foreign key (test_pk) references test(pk));
|
||||
|
||||
COPY test_info FROM STDIN WITH (HEADER);
|
||||
id info test_pk
|
||||
4 string for 4 1
|
||||
5 string for 5 0
|
||||
6 string for 6 0
|
||||
\.
|
||||
@@ -0,0 +1,16 @@
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE Regions (
|
||||
"Id" SERIAL UNIQUE NOT NULL,
|
||||
"Code" VARCHAR(4) UNIQUE NOT NULL,
|
||||
"Capital" VARCHAR(10) NOT NULL,
|
||||
"Name" VARCHAR(255) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
COPY regions ("Id", "Code", "Capital", "Name") FROM stdin;
|
||||
1 01 97105 Guadeloupe
|
||||
2 02 97209 Martinique
|
||||
3 03 97302 Guyane
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,48 @@
|
||||
BEGIN;
|
||||
|
||||
-- Database schema / Schéma de la base de données
|
||||
|
||||
-- Regions / Régions
|
||||
CREATE TABLE Regions (
|
||||
id SERIAL UNIQUE NOT NULL,
|
||||
code VARCHAR(4) UNIQUE NOT NULL,
|
||||
capital VARCHAR(10) NOT NULL, -- REFERENCES Towns (code),
|
||||
-- TODO: TEXT columns do not work correctly in Doltgres yet
|
||||
-- name TEXT UNIQUE NOT NULL
|
||||
name VARCHAR(255) UNIQUE NOT NULL
|
||||
);
|
||||
|
||||
SET client_encoding = 'utf-8';
|
||||
SET check_function_bodies = false;
|
||||
SET search_path = public, pg_catalog;
|
||||
|
||||
COPY regions (id, code, capital, name) FROM stdin;
|
||||
1 01 97105 Guadeloupe
|
||||
2 02 97209 Martinique
|
||||
3 03 97302 Guyane
|
||||
4 04 97411 La Réunion
|
||||
5 11 75056 Île-de-France
|
||||
6 21 51108 Champagne-Ardenne
|
||||
7 22 80021 Picardie
|
||||
8 23 76540 Haute-Normandie
|
||||
9 24 45234 Centre
|
||||
10 25 14118 Basse-Normandie
|
||||
11 26 21231 Bourgogne
|
||||
12 31 59350 Nord-Pas-de-Calais
|
||||
13 41 57463 Lorraine
|
||||
14 42 67482 Alsace
|
||||
15 43 25056 Franche-Comté
|
||||
16 52 44109 Pays de la Loire
|
||||
17 53 35238 Bretagne
|
||||
18 54 86194 Poitou-Charentes
|
||||
19 72 33063 Aquitaine
|
||||
20 73 31555 Midi-Pyrénées
|
||||
21 74 87085 Limousin
|
||||
22 82 69123 Rhône-Alpes
|
||||
23 83 63113 Auvergne
|
||||
24 91 34172 Languedoc-Roussillon
|
||||
25 93 13055 Provence-Alpes-Côte d'Azur
|
||||
26 94 2A004 Corse
|
||||
\.
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,430 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'doltgres: --help' {
|
||||
# just a smoke test
|
||||
doltgres --help
|
||||
}
|
||||
|
||||
@test 'doltgres: --config-help' {
|
||||
# just a smoke test
|
||||
doltgres --config-help
|
||||
}
|
||||
|
||||
@test 'doltgres: no arguments' {
|
||||
PORT=5432
|
||||
mkdir test-home
|
||||
# TODO: DOLT_ROOT_PATH behavior overrides the HOME behavior, which is confusing and not
|
||||
# applicable to Doltgres, fix it
|
||||
HOME=test-home DOLTGRES_DATA_DIR='' DOLT_ROOT_PATH='' doltgres > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
# databases should get created in home/doltgres/databases by default
|
||||
[ -d test-home/doltgres/databases/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: data-dir param' {
|
||||
PORT=5432
|
||||
DOLTGRES_DATA_DIR=fake doltgres --data-dir test > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ -d test/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: data dir in env var' {
|
||||
PORT=5432
|
||||
DOLTGRES_DATA_DIR=test doltgres > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ -d test/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: implicit config.yaml' {
|
||||
PORT=5434
|
||||
|
||||
cat > config.yaml <<EOF
|
||||
log_level: info
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
|
||||
data_dir: test
|
||||
EOF
|
||||
|
||||
doltgres > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ -d test/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: config.yaml without data dir' {
|
||||
PORT=5434
|
||||
|
||||
cat > config.yaml <<EOF
|
||||
log_level: info
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
|
||||
EOF
|
||||
|
||||
mkdir test-home
|
||||
HOME=test-home DOLTGRES_DATA_DIR='' DOLT_ROOT_PATH='' doltgres --config config.yaml > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ -d test-home/doltgres/databases/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: config file override with explicit config.yaml' {
|
||||
PORT=5434
|
||||
|
||||
cat > config-test.yaml <<EOF
|
||||
log_level: info
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
|
||||
data_dir: test
|
||||
EOF
|
||||
|
||||
# The only supported override right now is the data dir, add more here as we add more overrides
|
||||
doltgres --config config-test.yaml --data-dir local-override > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ ! -d test/postgres ]
|
||||
[ -d local-override/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: config file override with implicit config.yaml' {
|
||||
PORT=5434
|
||||
|
||||
cat > config.yaml <<EOF
|
||||
log_level: info
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
|
||||
data_dir: test
|
||||
EOF
|
||||
|
||||
# The only supported override right now is the data dir, add more here as we add more overrides
|
||||
doltgres --data-dir local-override > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
[ ! -d test/postgres ]
|
||||
[ -d local-override/postgres ]
|
||||
}
|
||||
|
||||
@test 'doltgres: config file' {
|
||||
PORT=$( definePORT )
|
||||
CONFIG=$( defineCONFIG $PORT )
|
||||
echo "$CONFIG" > config.yaml
|
||||
|
||||
cat config.yaml
|
||||
start_sql_server_with_args -config config.yaml > log.txt 2>&1
|
||||
|
||||
run cat log.txt
|
||||
[[ ! "$output" =~ "Author identity unknown" ]] || false
|
||||
[ -d "postgres" ]
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
}
|
||||
|
||||
@test 'doltgres: config file with all options' {
|
||||
PORT=$( definePORT )
|
||||
cat > config.yaml <<EOF
|
||||
log_level: info
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
tls_key: null
|
||||
tls_cert: null
|
||||
require_secure_transport: null
|
||||
allow_cleartext_passwords: null
|
||||
|
||||
performance:
|
||||
query_parallelism: null
|
||||
|
||||
data_dir: .
|
||||
|
||||
cfg_dir: .doltcfg
|
||||
|
||||
metrics:
|
||||
labels: {}
|
||||
host: null
|
||||
port: -1
|
||||
|
||||
remotesapi: {}
|
||||
|
||||
privilege_file: .doltcfg/privileges.db
|
||||
|
||||
auth_file: .doltcfg/auth.db
|
||||
|
||||
branch_control_file: .doltcfg/branch_control.db
|
||||
|
||||
user_session_vars: []
|
||||
|
||||
jwks: []
|
||||
EOF
|
||||
|
||||
cat config.yaml
|
||||
|
||||
start_sql_server_with_args -config config.yaml
|
||||
|
||||
query_server -c "create table t1 (a int primary key, b int)"
|
||||
query_server -c "insert into t1 values (1,2)"
|
||||
|
||||
run query_server -c "select * from t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
run test -f ".doltcfg/auth.db"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test 'doltgres: DOLTGRES_DATA_DIR set to current dir' {
|
||||
[ ! -d "postgres" ]
|
||||
export DOLTGRES_DATA_DIR="$(pwd)"
|
||||
start_sql_server > log.txt 2>&1
|
||||
|
||||
run cat log.txt
|
||||
[[ ! "$output" =~ "Author identity unknown" ]] || false
|
||||
[ -d "postgres" ]
|
||||
|
||||
run query_server -c "\l"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "postgres" ]] || false
|
||||
}
|
||||
|
||||
@test 'doltgres: user name and pass via env' {
|
||||
export DOLTGRES_USER="myuser"
|
||||
export DOLTGRES_PASSWORD="mypass"
|
||||
|
||||
[ ! -d "auth.db" ]
|
||||
|
||||
start_sql_server "" log.txt myuser mypass
|
||||
cat log.txt
|
||||
|
||||
# db matches user name since DOLTGRES_DB was not set
|
||||
query_server_for_user_and_pass myuser mypass myuser -c "create table myTable (a int);"
|
||||
|
||||
run query_server_for_user_and_pass myuser mypass myuser -c "insert into mytable values (1), (2)"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "INSERT" ]] || false
|
||||
|
||||
run query_server_for_user_and_pass postgres password myuser -c "insert into mytable values (1), (2)"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test 'doltgres: default db via env' {
|
||||
[ ! -d "auth.db" ]
|
||||
|
||||
start_sql_server mydb log.txt myuser
|
||||
cat log.txt
|
||||
|
||||
query_server_for_user_and_pass myuser password mydb -c "create table myTable (a int);"
|
||||
|
||||
run query_server_for_user_and_pass myuser password mydb -c "insert into mytable values (1), (2)"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "INSERT" ]] || false
|
||||
|
||||
run query_server_for_user_and_pass postgres password mydb -c "insert into mytable values (1), (2)"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
query_server_for_user_and_pass() {
|
||||
user=$1
|
||||
pass=$2
|
||||
db=$3
|
||||
shift
|
||||
shift
|
||||
shift
|
||||
|
||||
nativevar PGPASSWORD "$pass" /w
|
||||
psql -U "$user" -h localhost -p $PORT "$@" $db
|
||||
}
|
||||
|
||||
# Test for https://github.com/dolthub/doltgresql/issues/1863
|
||||
@test 'doltgres: connection to non-existent database fails' {
|
||||
start_sql_server
|
||||
|
||||
# Connecting to the default postgres database should work
|
||||
run query_server -c "SELECT 1"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Connecting to a non-existent database should fail
|
||||
nativevar PGPASSWORD "password" /w
|
||||
run psql -U postgres -h localhost -p $PORT -c "SELECT 1" nonexistent_db
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "does not exist" ]] || false
|
||||
}
|
||||
|
||||
@test 'doltgres: CREATE SCHEMA works on valid database' {
|
||||
start_sql_server
|
||||
|
||||
# CREATE SCHEMA should work on a valid database
|
||||
run query_server -c "CREATE SCHEMA test_schema_bats"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
# Verify schema was created
|
||||
run query_server -c "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'test_schema_bats'"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test_schema_bats" ]] || false
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'foreign-keys: survives restarts' {
|
||||
PORT=$( definePORT )
|
||||
|
||||
# stopping the server undefines the port, so save it
|
||||
port=$PORT
|
||||
mkdir test-home
|
||||
|
||||
CONFIG=$( defineCONFIG $PORT )
|
||||
echo "$CONFIG" > config.yaml
|
||||
|
||||
doltgres > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
cat server.out
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
query_server -c "create table parent (a int primary key, b int)"
|
||||
query_server -c "insert into parent values (1,2)"
|
||||
query_server -c "create table child (c int primary key, d int, foreign key (d) references public.parent(a))"
|
||||
query_server -c "insert into child values (2,1)"
|
||||
|
||||
stop_sql_server
|
||||
|
||||
PORT=$port
|
||||
doltgres > server.out 2>&1 &
|
||||
SERVER_PID=$!
|
||||
run wait_for_connection $PORT 7500
|
||||
|
||||
run query_server -c "insert into child values (100,100)"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "violation" ]] || false
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
query_server <<SQL
|
||||
CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 SMALLINT);
|
||||
INSERT INTO test1 VALUES (1, 2), (6, 7);
|
||||
SQL
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
|
||||
@test 'pgcatalog: tables do not include data from other databases' {
|
||||
run query_server --csv -c "SELECT current_database();"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "current_database" ]] || false
|
||||
[[ "$output" =~ "postgres" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
|
||||
run query_server --csv -c "SELECT attname FROM pg_catalog.pg_attribute WHERE attname = 'pk' and attrelid not in (select oid from pg_catalog.pg_class where left(relname, 5) = 'dolt_');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "attname" ]] || false
|
||||
[[ "$output" =~ "pk" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
|
||||
run query_server --csv -c "SELECT relname FROM pg_catalog.pg_class WHERE relname = 'test1';"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "relname" ]] || false
|
||||
[[ "$output" =~ "test1" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
|
||||
run query_server -c "CREATE DATABASE newdb;"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run query_server_for_db newdb --csv -c "SELECT current_database();"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "current_database" ]] || false
|
||||
[[ "$output" =~ "newdb" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
|
||||
run query_server_for_db newdb --csv -c "SELECT attname FROM pg_catalog.pg_attribute WHERE attname = 'pk';"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "attname" ]] || false
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
|
||||
run query_server_for_db newdb --csv -c "SELECT relname FROM pg_catalog.pg_class WHERE relname = 'test1';"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "relname" ]] || false
|
||||
[ "${#lines[@]}" -eq 1 ]
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
query_server <<SQL
|
||||
CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 SMALLINT);
|
||||
CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 INTEGER, v2 SMALLINT);
|
||||
INSERT INTO test1 VALUES (1, 2), (6, 7);
|
||||
INSERT INTO test2 VALUES (3, 4, 5), (8, 9, 0);
|
||||
CREATE VIEW testview AS SELECT * FROM test1;
|
||||
SQL
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'psql-commands: \l' {
|
||||
run query_server -c "\l"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "postgres" ]] || false
|
||||
}
|
||||
|
||||
@test 'psql-commands: \dt' {
|
||||
run query_server --csv -c "\dt"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "public,test1,table,postgres" ]] || false
|
||||
[[ "$output" =~ "public,test2,table,postgres" ]] || false
|
||||
}
|
||||
|
||||
@test 'psql-commands: \dt table' {
|
||||
run query_server --csv -c "\dt test2"
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "public,test2,table,postgres" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
}
|
||||
|
||||
@test 'psql-commands: \d' {
|
||||
run query_server --csv -c "\d"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "public,test1,table,postgres" ]] || false
|
||||
[[ "$output" =~ "public,test2,table,postgres" ]] || false
|
||||
[[ "$output" =~ "public,testview,view,postgres" ]] || false
|
||||
}
|
||||
|
||||
@test 'psql-commands: \d table' {
|
||||
skip "this command has not yet been implemented"
|
||||
}
|
||||
|
||||
@test 'psql-commands: \dn' {
|
||||
run query_server --csv -c "\dn"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt,postgres" ]] || false
|
||||
[[ "$output" =~ "public,postgres" ]] || false
|
||||
[ "${#lines[@]}" -eq 3 ]
|
||||
}
|
||||
|
||||
@test 'psql-commands: \df' {
|
||||
run query_server -c "\df"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0 rows" ]] || false
|
||||
}
|
||||
|
||||
@test 'psql-commands: \dv' {
|
||||
run query_server --csv -c "\dv"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "public,testview,view,postgres" ]] || false
|
||||
[ "${#lines[@]}" -eq 2 ]
|
||||
}
|
||||
|
||||
@test 'psql-commands: \du' {
|
||||
skip "users have not yet been implemented"
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
# This test exercises the push/pull/clone workflow across two independent Doltgres server
|
||||
# processes, each with its own data directory, coordinating only through a shared
|
||||
# file-system remote.
|
||||
@test 'remotes-file-system: clone from a fresh server, then push/pull round-trip data, a sequence, an enum type, and a function' {
|
||||
mkdir remote
|
||||
REMOTE_URL="file://$(pwd)/remote"
|
||||
|
||||
# --- Server A: seed a table, a sequence, a custom enum type, and a user-defined function --
|
||||
# (all serialized at the Doltgres layer, not the Dolt layer -- see core/rootobject) -- commit,
|
||||
# and push to the file-system remote ---
|
||||
mkdir serverA
|
||||
cd serverA
|
||||
start_sql_server
|
||||
query_server <<SQL
|
||||
CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');
|
||||
CREATE FUNCTION double_it(x INT) RETURNS INT AS \$\$ BEGIN RETURN x * 2; END; \$\$ LANGUAGE plpgsql;
|
||||
CREATE TABLE items (id INT PRIMARY KEY, label TEXT NOT NULL, feeling mood);
|
||||
INSERT INTO items VALUES (1, 'apple', 'happy'), (2, 'banana', 'sad');
|
||||
CREATE SEQUENCE counter START 100 INCREMENT 50;
|
||||
SELECT nextval('counter'); -- advances to 100
|
||||
SELECT dolt_commit('-Am', 'seed items, counter, mood type, and double_it function');
|
||||
SELECT dolt_remote('add', 'origin', '$REMOTE_URL');
|
||||
SELECT dolt_push('origin', 'main');
|
||||
SQL
|
||||
stop_sql_server
|
||||
cd ..
|
||||
|
||||
# --- Server B: an entirely separate, freshly-started server with its own data directory;
|
||||
# it shares no process, session, or in-memory state with server A. Clone from the remote. ---
|
||||
mkdir serverB
|
||||
cd serverB
|
||||
start_sql_server
|
||||
query_server -c "SELECT dolt_clone('$REMOTE_URL', 'cloned');"
|
||||
|
||||
# The enum type definition itself (not just data using it) must have transferred. Checked as
|
||||
# separate substrings (rather than one "id | label | feeling" string) because psql's tuples-only
|
||||
# output pads each column to its widest value ("apple" pads out to match "banana"'s width), so
|
||||
# the exact spacing between columns isn't stable across rows.
|
||||
run query_server_for_db cloned -t -c "SELECT id, label, feeling::text FROM items ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | apple" ]] || false
|
||||
[[ "$output" =~ "happy" ]] || false
|
||||
[[ "$output" =~ "2 | banana" ]] || false
|
||||
[[ "$output" =~ "sad" ]] || false
|
||||
|
||||
# The user-defined function must also be callable post-clone.
|
||||
run query_server_for_db cloned -c "SELECT double_it(21);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "42" ]] || false
|
||||
|
||||
# Must reflect server A's current value (100), not reset to the sequence's start value. Read
|
||||
# via pg_sequences rather than calling nextval() here, since nextval() itself writes the
|
||||
# sequence's current value and would leave the clone with an uncommitted change, which the
|
||||
# pull below would then reject with "cannot merge with uncommitted changes".
|
||||
run query_server_for_db cloned -c "SELECT last_value FROM pg_sequences WHERE sequencename = 'counter';"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "100" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
cd ..
|
||||
|
||||
# --- Back on server A: advance the table (using the enum type again) and the sequence
|
||||
# further, and push again ---
|
||||
cd serverA
|
||||
start_sql_server
|
||||
query_server <<SQL
|
||||
INSERT INTO items VALUES (3, 'cherry', 'ok');
|
||||
SELECT nextval('counter'); -- advances to 150
|
||||
SELECT dolt_commit('-Am', 'add cherry and advance counter');
|
||||
SELECT dolt_push('origin', 'main');
|
||||
SQL
|
||||
stop_sql_server
|
||||
cd ..
|
||||
|
||||
# --- Back on server B (also restarted fresh): pull the update into the clone ---
|
||||
cd serverB
|
||||
start_sql_server
|
||||
run query_server_for_db cloned -c "SELECT dolt_pull('origin');"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run query_server_for_db cloned -t -c "SELECT id, label, feeling::text FROM items ORDER BY id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | apple" ]] || false
|
||||
[[ "$output" =~ "happy" ]] || false
|
||||
[[ "$output" =~ "2 | banana" ]] || false
|
||||
[[ "$output" =~ "sad" ]] || false
|
||||
[[ "$output" =~ "3 | cherry" ]] || false
|
||||
[[ "$output" =~ "ok" ]] || false
|
||||
|
||||
# The function keeps working after an incremental pull too, not just right after clone.
|
||||
run query_server_for_db cloned -c "SELECT double_it(10);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "20" ]] || false
|
||||
|
||||
# The pull must have carried server A's advanced current value (150), not left the clone's own.
|
||||
run query_server_for_db cloned -c "SELECT last_value FROM pg_sequences WHERE sequencename = 'counter';"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "150" ]] || false
|
||||
|
||||
# No further pull happens after this, so it's now safe to call nextval() directly: must
|
||||
# continue from 150 (next is 200), proving the synced state drives future values correctly too.
|
||||
run query_server_for_db cloned -c "SELECT nextval('counter');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "200" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
cd ..
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
log_level: debug
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
user:
|
||||
name: "postgres"
|
||||
password: "password"
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: 5433
|
||||
read_timeout_millis: 28800000
|
||||
write_timeout_millis: 28800000
|
||||
|
||||
data_dir: .
|
||||
|
||||
cfg_dir: .doltcfg
|
||||
|
||||
metrics:
|
||||
labels: {}
|
||||
host: null
|
||||
port: -1
|
||||
|
||||
postgres_replication:
|
||||
postgres_server_address: 127.0.0.1
|
||||
postgres_user: postgres
|
||||
postgres_password: password
|
||||
postgres_database: postgres
|
||||
postgres_port: 5432
|
||||
slot_name: doltgres_slot
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
# tests are run without setting doltgres config user.name and user.email
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'replication: test postgres connection' {
|
||||
if [[ ! -v "RUN_DOLTGRES_REPLICATION_TESTS" ]]; then
|
||||
skip "RUN_DOLTGRES_REPLICATION_TESTS not set, skipping"
|
||||
fi
|
||||
|
||||
# setup the postgres primary
|
||||
postgres_primary_query "drop table if exists t1"
|
||||
postgres_primary_query "create table t1 (a int primary key, b int)"
|
||||
postgres_primary_query "DROP PUBLICATION IF EXISTS doltgres_slot"
|
||||
postgres_primary_query "CREATE PUBLICATION doltgres_slot FOR TABLE t1"
|
||||
run postgres_primary_query "DROP_REPLICATION_SLOT doltgres_slot" # ignore errors if the slot doesn't exist
|
||||
postgres_primary_query "CREATE_REPLICATION_SLOT doltgres_slot LOGICAL pgoutput"
|
||||
|
||||
# This host may have a history, and we don't want to start replicating from the beginning of
|
||||
# history, just from the current WAL position. So seed that state here.
|
||||
LSN=$(postgres_primary_query "SELECT pg_current_wal_lsn()" -t)
|
||||
|
||||
if [[ ! -d ./.doltcfg ]]; then
|
||||
mkdir ./.doltcfg
|
||||
fi
|
||||
echo $LSN > ./.doltcfg/pg_wal_location
|
||||
|
||||
cat ./.doltcfg/pg_wal_location
|
||||
|
||||
cp "$BATS_TEST_DIRNAME/replication-config.yaml" "$BATS_TMPDIR/dolt-repo-$$"
|
||||
PORT=5433
|
||||
start_sql_server_with_args "-config=replication-config.yaml"
|
||||
|
||||
# Create the table that already exists on the primary before doing any inserts on the primary
|
||||
query_server postgres -c "create table public.t1 (a int primary key, b int)"
|
||||
|
||||
# this insert on the primary should now replicate to the replica
|
||||
postgres_primary_query "insert into t1 values (1, 2)"
|
||||
sleep 1
|
||||
|
||||
query_server postgres -c "select * from public.t1" -t
|
||||
run query_server postgres -c "select * from public.t1" -t
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1 | 2" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
}
|
||||
|
||||
postgres_primary_query() {
|
||||
PGPASSWORD="password" psql -U "postgres" -h 127.0.0.1 -p 5432 "dbname=postgres replication=database" -c "$@" doltgres
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'root-objects: dolt_add, dolt_branch, dolt_checkout, dolt_commit, dolt_reset' {
|
||||
query_server <<SQL
|
||||
CREATE SEQUENCE test;
|
||||
SELECT setval('test', 10);
|
||||
SQL
|
||||
run query_server -c "SELECT nextval('test');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "11" ]] || false
|
||||
|
||||
query_server -c "SELECT dolt_add('test');"
|
||||
run query_server -c "SELECT length(dolt_commit('-m', 'initial')::text);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "34" ]] || false
|
||||
|
||||
query_server -c "SELECT dolt_branch('other');"
|
||||
query_server -c "SELECT setval('test', 20);"
|
||||
query_server -c "SELECT dolt_add('.');"
|
||||
run query_server -c "SELECT length(dolt_commit('-m', 'next')::text);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "34" ]] || false
|
||||
|
||||
run query_server -c "SELECT nextval('test');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "21" ]] || false
|
||||
|
||||
run query_server <<SQL
|
||||
SELECT dolt_checkout('other');
|
||||
SELECT nextval('test');
|
||||
SQL
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "12" ]] || false
|
||||
}
|
||||
|
||||
@test 'root-objects: start and stop' {
|
||||
query_server <<SQL
|
||||
CREATE SEQUENCE test;
|
||||
SELECT setval('test', 10);
|
||||
SQL
|
||||
run query_server -c "SELECT nextval('test');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "11" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
start_sql_server
|
||||
query_server -c "SELECT dolt_add('test');"
|
||||
run query_server -c "SELECT length(dolt_commit('-m', 'initial')::text);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "34" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
start_sql_server
|
||||
query_server -c "SELECT dolt_branch('other');"
|
||||
query_server -c "SELECT setval('test', 20);"
|
||||
query_server -c "SELECT dolt_add('.');"
|
||||
run query_server -c "SELECT length(dolt_commit('-m', 'next')::text);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "34" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
start_sql_server
|
||||
run query_server -c "SELECT nextval('test');"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "21" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
start_sql_server
|
||||
run query_server <<SQL
|
||||
SELECT dolt_checkout('other');
|
||||
SELECT nextval('test');
|
||||
SQL
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "12" ]] || false
|
||||
}
|
||||
|
||||
@test 'root-objects: \d does not break' {
|
||||
query_server <<SQL
|
||||
CREATE TABLE "t" ("id" SERIAL);
|
||||
SQL
|
||||
run query_server -c "\d"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "sequence" ]] || false
|
||||
|
||||
stop_sql_server
|
||||
start_sql_server
|
||||
run query_server -c "\d"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "sequence" ]] || false
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
script_dir=$(dirname "$0")
|
||||
cd $script_dir/../
|
||||
|
||||
ERRORS_FOUND=0
|
||||
for FILENAME_WITH_EXT in *.bats; do
|
||||
FILENAME=${FILENAME_WITH_EXT%".bats"}
|
||||
while read -r LINE; do
|
||||
if [[ ! "$LINE" =~ "@test \"$FILENAME:" ]] && [[ -n "$LINE" ]]; then
|
||||
TESTNAME=$(echo "$LINE" | cut -d'"' -f 2)
|
||||
echo -e "ERROR: test \"$TESTNAME\" in \"$FILENAME_WITH_EXT\" must start with \"$FILENAME:\" in the title"
|
||||
ERRORS_FOUND=1
|
||||
fi
|
||||
done <<< $(grep '@test "' "$FILENAME_WITH_EXT")
|
||||
while read -r LINE; do
|
||||
if [[ ! "$LINE" =~ "@test '$FILENAME:" ]] && [[ -n "$LINE" ]]; then
|
||||
TESTNAME=$(echo "$LINE" | cut -d"'" -f 2)
|
||||
echo -e "ERROR: test \"$TESTNAME\" in \"$FILENAME_WITH_EXT\" must start with \"$FILENAME:\" in the title"
|
||||
ERRORS_FOUND=1
|
||||
fi
|
||||
done <<< $(grep "@test '" "$FILENAME_WITH_EXT")
|
||||
done
|
||||
if [[ $ERRORS_FOUND -eq 1 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
@@ -0,0 +1,72 @@
|
||||
load setup/windows-compat
|
||||
load setup/query-server-common
|
||||
|
||||
if [ -z "$BATS_TMPDIR" ]; then
|
||||
export BATS_TMPDIR=$HOME/batstmp/
|
||||
mkdir $BATS_TMPDIR
|
||||
fi
|
||||
|
||||
nativebatsdir() { echo `nativepath $BATS_TEST_DIRNAME/$1`; }
|
||||
batshelper() { echo `nativebatsdir helper/$1`; }
|
||||
|
||||
setup_common() {
|
||||
psql --version
|
||||
|
||||
export PATH=$PATH:~/go/bin
|
||||
cd $BATS_TMPDIR
|
||||
|
||||
# remove directory if exists
|
||||
# reruns recycle pids
|
||||
rm -rf "dolt-repo-$$"
|
||||
|
||||
# Append the directory name with the pid of the calling process so
|
||||
# multiple tests can be run in parallel on the same machine
|
||||
mkdir "dolt-repo-$$"
|
||||
cd "dolt-repo-$$"
|
||||
nativevar DOLTGRES_DATA_DIR "$(pwd)" /p
|
||||
|
||||
if [ -z "$DOLT_TEST_RETRIES" ]; then
|
||||
export BATS_TEST_RETRIES="$DOLT_TEST_RETRIES"
|
||||
fi
|
||||
}
|
||||
|
||||
teardown_common() {
|
||||
# rm -rf can fail with a "directory not empty" error in some cases. This seems to be a misleading
|
||||
# error message; the real error is that a file is still in use. Instead of waiting longer for
|
||||
# any processes to finish, we just ignore any error removing temp files and use 'true' as the last
|
||||
# command in this function to ensure that teardown_common doesn't fail a test just because we
|
||||
# couldn't delete any temporary test files.
|
||||
stop_sql_server
|
||||
rm -rf "$BATS_TMPDIR/dolt-repo-$$"
|
||||
true
|
||||
}
|
||||
|
||||
query_server() {
|
||||
nativevar PGPASSWORD "password" /w
|
||||
psql -U "${SQL_USER:-postgres}" -h localhost -p $PORT "$@" postgres
|
||||
}
|
||||
|
||||
query_server_for_db() {
|
||||
nativevar PGPASSWORD "password" /w
|
||||
local db_name=${1:-postgres}
|
||||
shift
|
||||
psql -U "${SQL_USER:-postgres}" -h localhost -p $PORT "$@" $db_name
|
||||
}
|
||||
|
||||
log_status_eq() {
|
||||
if ! [ "$status" -eq $1 ]; then
|
||||
echo "status: expected $1, received $status"
|
||||
printf "output:\n$output"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
log_output_has() {
|
||||
if ! [[ "$output" =~ $1 ]]; then
|
||||
echo "output did not have $1"
|
||||
printf "output:\n$output"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
nativevar DOLT_ROOT_PATH $BATS_TMPDIR/config-$$ /p
|
||||
@@ -0,0 +1,144 @@
|
||||
SERVER_REQS_INSTALLED="FALSE"
|
||||
SERVER_PID=""
|
||||
DEFAULT_DB=""
|
||||
PASSWORD=""
|
||||
USERNAME=""
|
||||
|
||||
# wait_for_connection(<PORT>, <TIMEOUT IN MS>) attempts to connect to the sql-server at the specified
|
||||
# port on localhost, using the $SQL_USER (or 'postgres' if unspecified) as the user name, and trying once
|
||||
# per second until the millisecond timeout is reached. If a connection is successfully established,
|
||||
# this function returns 0. If a connection was not able to be established within the timeout period,
|
||||
# this function returns 1.
|
||||
wait_for_connection() {
|
||||
port=$1
|
||||
timeout=$2
|
||||
end_time=$((SECONDS+($timeout/1000)))
|
||||
USERNAME="${USERNAME:=postgres}"
|
||||
PASSWORD="${PASSWORD:=password}"
|
||||
|
||||
nativevar PGPASSWORD "$PASSWORD" /w
|
||||
|
||||
while [ $SECONDS -lt $end_time ]; do
|
||||
run psql -U $USERNAME -h localhost -p $port -c "SELECT 1;" $DEFAULT_DB
|
||||
if [ $status -eq 0 ]; then
|
||||
echo "Connected successfully!"
|
||||
return 0
|
||||
else
|
||||
echo "$output"
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Failed to connect to database $DEFAULT_DB on port $port within $timeout ms."
|
||||
return 1
|
||||
}
|
||||
|
||||
start_sql_server() {
|
||||
DEFAULT_DB="$1"
|
||||
logFile=$2
|
||||
USERNAME=$3
|
||||
PASSWORD=$4
|
||||
|
||||
if [ -n "$DEFAULT_DB" ]; then
|
||||
nativevar DOLTGRES_DB "$DEFAULT_DB" /w
|
||||
fi
|
||||
|
||||
if [ -n "$PASSWORD" ]; then
|
||||
nativevar PGPASSWORD "password" /w
|
||||
nativevar DOLTGRES_PASSWORD "$PASSWORD" /w
|
||||
else
|
||||
nativevar PGPASSWORD "$PASSWORD" /w
|
||||
PASSWORD="password"
|
||||
fi
|
||||
|
||||
if [ -n "$USERNAME" ]; then
|
||||
nativevar DOLTGRES_USER "$USERNAME" /w
|
||||
if [ -z "$DEFAULT_DB" ]; then
|
||||
DEFAULT_DB="$USERNAME"
|
||||
fi
|
||||
else
|
||||
USERNAME="postgres"
|
||||
fi
|
||||
|
||||
DEFAULT_DB="${DEFAULT_DB:=postgres}"
|
||||
|
||||
PORT=$( definePORT )
|
||||
CONFIG=$( defineCONFIG $PORT )
|
||||
echo "$CONFIG" > config.yaml
|
||||
if [[ $logFile ]]
|
||||
then
|
||||
doltgres -data-dir=. -config=config.yaml> $logFile 2>&1 &
|
||||
else
|
||||
doltgres -data-dir=. -config=config.yaml &
|
||||
fi
|
||||
SERVER_PID=$!
|
||||
wait_for_connection $PORT 7500
|
||||
}
|
||||
|
||||
# like start_sql_server, but the second argument is a string with all arguments to doltgres. The
|
||||
# port argument is handled separately: if the variable $PORT is not defined and the --port argument
|
||||
# is not included in the argument list, a random port is chosen for $PORT and the argument --port is
|
||||
# appended to the argument list.
|
||||
start_sql_server_with_args() {
|
||||
DEFAULT_DB=""
|
||||
nativevar DEFAULT_DB "$DEFAULT_DB" /w
|
||||
nativevar PGPASSWORD "password" /w
|
||||
|
||||
echo "running doltgres $@"
|
||||
doltgres "$@" &
|
||||
SERVER_PID=$!
|
||||
wait_for_connection $PORT 7500
|
||||
}
|
||||
|
||||
# stop_sql_server stops the SQL server. For cases where it's important
|
||||
# to wait for the process to exit after the kill signal (e.g. waiting
|
||||
# for an async replication push), pass 1.
|
||||
# kill the process if it's still running
|
||||
stop_sql_server() {
|
||||
# Clean up any mysql.sock file in the default, global location
|
||||
if [ -f "/tmp/mysql.sock" ]; then rm -f /tmp/mysql.sock; fi
|
||||
if [ -f "/tmp/postgres.sock" ]; then rm -f /tmp/mysql.sock; fi
|
||||
if [ -f "/tmp/dolt.$PORT.sock" ]; then rm -f /tmp/dolt.$PORT.sock; fi
|
||||
|
||||
wait=$1
|
||||
if [ ! -z "$SERVER_PID" ]; then
|
||||
# ignore failures of kill command in the case the server is already dead
|
||||
run kill $SERVER_PID
|
||||
if [ $wait ]; then
|
||||
while ps -p $SERVER_PID > /dev/null; do
|
||||
sleep .1;
|
||||
done
|
||||
fi;
|
||||
fi
|
||||
SERVER_PID=
|
||||
PORT=
|
||||
}
|
||||
|
||||
definePORT() {
|
||||
for i in {0..99}
|
||||
do
|
||||
port=$((RANDOM % 4096 + 2048))
|
||||
# nc (netcat) returns 0 when it _can_ connect to a port (therefore in use), 1 otherwise.
|
||||
run nc -z localhost $port
|
||||
if [ "$status" -eq 1 ]; then
|
||||
echo $port
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
defineCONFIG() {
|
||||
PORT=$1
|
||||
cat <<EOF
|
||||
log_level: debug
|
||||
|
||||
behavior:
|
||||
read_only: false
|
||||
disable_client_multi_statements: false
|
||||
dolt_transaction_commit: false
|
||||
|
||||
listener:
|
||||
host: localhost
|
||||
port: $PORT
|
||||
EOF
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
nativepath() { echo "$1"; }
|
||||
nativevar() { eval export "$1"="$2"; }
|
||||
skiponwindows() { :; }
|
||||
|
||||
IS_WINDOWS=${IS_WINDOWS:-false}
|
||||
WINDOWS_BASE_DIR=${WINDOWS_BASE_DIR:-/mnt/c}
|
||||
|
||||
if [ -d "$WINDOWS_BASE_DIR"/Windows/System32 ] || [ "$IS_WINDOWS" == true ]; then
|
||||
IS_WINDOWS=true
|
||||
if [ ! -d "$WINDOWS_BASE_DIR"/batstmp ]; then
|
||||
mkdir "$WINDOWS_BASE_DIR"/batstmp
|
||||
fi
|
||||
BATS_TMPDIR=`TMPDIR="$WINDOWS_BASE_DIR"/batstmp mktemp -d -t dolt-bats-tests-XXXXXX`
|
||||
export BATS_TMPDIR
|
||||
nativepath() {
|
||||
wslpath -w "$1"
|
||||
}
|
||||
nativevar() {
|
||||
eval export "$1"="$2"
|
||||
export WSLENV="$WSLENV:$1$3"
|
||||
}
|
||||
skiponwindows() {
|
||||
skip "$1"
|
||||
}
|
||||
fi
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'types: boolean type' {
|
||||
query_server <<SQL
|
||||
CREATE TABLE t_boolean (id INTEGER primary key, v1 BOOLEAN);
|
||||
INSERT INTO t_boolean VALUES (1, 'true'), (2, 'false');
|
||||
SQL
|
||||
|
||||
run query_server --csv -c "SELECT * FROM t_boolean;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1,t" ]] || false
|
||||
[[ "$output" =~ "2,f" ]] || false
|
||||
}
|
||||
|
||||
@test 'types: boolean array type' {
|
||||
query_server <<SQL
|
||||
CREATE TABLE t_boolean_array (id INTEGER primary key, v1 BOOLEAN[]);
|
||||
INSERT INTO t_boolean_array VALUES (1, ARRAY[true, false]), (2, ARRAY[false, true]), (3, ARRAY[true, true]), (4, ARRAY[false, false]), (5, ARRAY[true]), (6, ARRAY[false]);
|
||||
SQL
|
||||
|
||||
run query_server --csv -c "SELECT * FROM t_boolean_array;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ '1,"{t,f}"' ]] || false
|
||||
[[ "$output" =~ '2,"{f,t}"' ]] || false
|
||||
[[ "$output" =~ '3,"{t,t}"' ]] || false
|
||||
[[ "$output" =~ '4,"{f,f}"' ]] || false
|
||||
[[ "$output" =~ '5,{t}' ]] || false
|
||||
[[ "$output" =~ '6,{f}' ]] || false
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test 'values: mixed int and decimal' {
|
||||
# Integer first, then decimal - should resolve to numeric
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(2.01),(3)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.01" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: decimal first then int' {
|
||||
# Decimal first, then integers - should resolve to numeric
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1.01),(2),(3)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1.01" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: SUM with mixed types' {
|
||||
# SUM should work directly now that VALUES has correct type
|
||||
run query_server -t -c "SELECT SUM(n) FROM (VALUES(1),(2.01),(3)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "6.01" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: multiple columns mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1, 'a'), (2.5, 'b')) v(num, str);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "a" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "b" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: SUM with explicit cast' {
|
||||
run query_server -t -c "SELECT SUM(n::numeric) FROM (VALUES(1),(2.01),(3)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "6.01" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: MIN and MAX with mixed types' {
|
||||
run query_server -t -c "SELECT MIN(n), MAX(n) FROM (VALUES(1),(2.5),(3),(0.5)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "0.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: GROUP BY with mixed types' {
|
||||
run query_server -t -c "SELECT n, COUNT(*) FROM (VALUES(1),(2.5),(1),(3.5),(2.5)) v(n) GROUP BY n ORDER BY n;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "3.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: SUM GROUP BY with mixed types' {
|
||||
run query_server -t -c "SELECT category, SUM(amount) FROM (VALUES('a', 1),('b', 2.5),('a', 3),('b', 4.5)) v(category, amount) GROUP BY category ORDER BY category;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "a" ]] || false
|
||||
[[ "$output" =~ "4" ]] || false
|
||||
[[ "$output" =~ "b" ]] || false
|
||||
[[ "$output" =~ "7.0" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: DISTINCT with mixed types' {
|
||||
run query_server -t -c "SELECT DISTINCT n FROM (VALUES(1),(2.5),(1),(2.5),(3)) v(n) ORDER BY n;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: ORDER BY with mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(3),(1.5),(2),(4.5)) v(n) ORDER BY n;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1.5" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "4.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: ORDER BY DESC with mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(3),(1.5),(2),(4.5)) v(n) ORDER BY n DESC;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "4.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "1.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: LIMIT with mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) LIMIT 3;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
! [[ "$output" =~ "4.5" ]] || false
|
||||
! [[ "$output" =~ " 5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: WHERE filter with mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) WHERE n > 2;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "4.5" ]] || false
|
||||
[[ "$output" =~ "5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: NULLs with mixed types' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(NULL),(2.5)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: all same type no cast needed' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(2),(3)) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: all string literals' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES('a'),('b'),('c')) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "a" ]] || false
|
||||
[[ "$output" =~ "b" ]] || false
|
||||
[[ "$output" =~ "c" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: string concatenation' {
|
||||
run query_server -t -c "SELECT n || '!' FROM (VALUES('hello'),('world')) v(n);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "hello!" ]] || false
|
||||
[[ "$output" =~ "world!" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: type mismatch bool and int errors' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(true),(1),(false)) v(n);"
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "cannot be matched" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: JOIN with same types' {
|
||||
run query_server -t -c "SELECT a.n, b.label FROM (VALUES(1),(2),(3)) a(n) JOIN (VALUES(1, 'one'),(2, 'two'),(3, 'three')) b(id, label) ON a.n = b.id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "one" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "two" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "three" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: JOIN with mixed types' {
|
||||
run query_server -t -c "SELECT a.n, b.label FROM (VALUES(1),(2.5),(3)) a(n) JOIN (VALUES(1, 'one'),(3, 'three')) b(id, label) ON a.n = b.id;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "one" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "three" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: CTE with mixed types' {
|
||||
run query_server -t -c "WITH nums AS (SELECT * FROM (VALUES(1),(2.5),(3)) v(n)) SELECT * FROM nums;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: CTE SUM with mixed types' {
|
||||
run query_server -t -c "WITH nums AS (SELECT * FROM (VALUES(1),(2.5),(3)) v(n)) SELECT SUM(n) FROM nums;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "6.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: multi-column partial cast' {
|
||||
# Only second column needs cast, first stays int
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1, 10),(2, 20.5),(3, 30)) v(a, b);"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "10" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
[[ "$output" =~ "20.5" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "30" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: combined GROUP BY ORDER BY LIMIT' {
|
||||
run query_server -t -c "SELECT n, COUNT(*) as cnt FROM (VALUES(1),(2.5),(1),(2.5),(3),(1)) v(n) GROUP BY n ORDER BY cnt DESC LIMIT 2;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "1" ]] || false
|
||||
[[ "$output" =~ "3" ]] || false
|
||||
[[ "$output" =~ "2.5" ]] || false
|
||||
[[ "$output" =~ "2" ]] || false
|
||||
}
|
||||
|
||||
@test 'values: combined WHERE ORDER BY LIMIT' {
|
||||
run query_server -t -c "SELECT * FROM (VALUES(1),(2.5),(3),(4.5),(5)) v(n) WHERE n > 1 ORDER BY n DESC LIMIT 2;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "5" ]] || false
|
||||
[[ "$output" =~ "4.5" ]] || false
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/setup/common.bash
|
||||
|
||||
setup() {
|
||||
setup_common
|
||||
start_sql_server
|
||||
query_server <<SQL
|
||||
CREATE TABLE test1 (pk BIGINT PRIMARY KEY, v1 SMALLINT);
|
||||
CREATE TABLE test2 (pk BIGINT PRIMARY KEY, v1 INTEGER, v2 SMALLINT);
|
||||
INSERT INTO test1 VALUES (1, 2), (6, 7);
|
||||
INSERT INTO test2 VALUES (3, 4, 5), (8, 9, 0);
|
||||
CREATE VIEW testview AS SELECT * FROM test1;
|
||||
SQL
|
||||
}
|
||||
|
||||
teardown() {
|
||||
teardown_common
|
||||
}
|
||||
|
||||
# Function to extract and verify the first line (column name)
|
||||
verify_column_name() {
|
||||
local output=$1
|
||||
local expected_column_name=$2
|
||||
|
||||
# Extract the first line and trim leading and trailing whitespace
|
||||
local first_line=$(echo "$output" | head -n 1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
||||
|
||||
# Verify the first line matches the expected column name
|
||||
[ "$first_line" = "$expected_column_name" ] || return 1
|
||||
}
|
||||
|
||||
@test 'workbench-commands: version' {
|
||||
run query_server -c "SELECT version();"
|
||||
[ "$status" -eq 0 ]
|
||||
# Ensure the column name is 'version' and not 'version()'
|
||||
verify_column_name "$output" "version"
|
||||
[[ "$output" =~ "PostgreSQL 15.5" ]] || false
|
||||
}
|
||||
|
||||
@test 'workbench-commands: current_schema' {
|
||||
run query_server -c "SELECT * FROM current_schema()"
|
||||
[ "$status" -eq 0 ]
|
||||
verify_column_name "$output" "current_schema"
|
||||
[[ "$output" =~ "public" ]] || false
|
||||
|
||||
run query_server <<SQL
|
||||
CREATE SCHEMA test_schema;
|
||||
SET search_path TO test_schema;
|
||||
SELECT * FROM current_schema();
|
||||
SQL
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "test_schema" ]] || false
|
||||
}
|
||||
|
||||
@test 'workbench-commands: current_database' {
|
||||
run query_server -c "SELECT * FROM current_database();"
|
||||
[ "$status" -eq 0 ]
|
||||
verify_column_name "$output" "current_database"
|
||||
[[ "$output" =~ "postgres" ]] || false
|
||||
|
||||
run query_server -c "CREATE DATABASE newdb;"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run query_server_for_db newdb -c "SELECT * FROM current_database()"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "newdb" ]] || false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
// Copyright 2024 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package _dataloader
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/memory"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/doltgresql/core/dataloader"
|
||||
"github.com/dolthub/doltgresql/server/initialization"
|
||||
"github.com/dolthub/doltgresql/server/types"
|
||||
doltgresservercfg "github.com/dolthub/doltgresql/servercfg"
|
||||
)
|
||||
|
||||
// TestCsvDataLoader tests the CsvDataLoader implementation.
|
||||
func TestCsvDataLoader(t *testing.T) {
|
||||
db := memory.NewDatabase("mydb")
|
||||
provider := memory.NewDBProvider(db)
|
||||
initialization.Initialize(nil, doltgresservercfg.DefaultServerConfig())
|
||||
|
||||
ctx := &sql.Context{
|
||||
Context: context.Background(),
|
||||
Session: memory.NewSession(sql.NewBaseSession(), provider),
|
||||
}
|
||||
|
||||
pkCols := []string{"pk", "c1", "c2"}
|
||||
pkSchema := sql.NewPrimaryKeySchema(sql.Schema{
|
||||
{Name: "pk", Type: types.Int64, Source: "source1"},
|
||||
{Name: "c1", Type: types.Int64, Source: "source1"},
|
||||
{Name: "c2", Type: types.VarChar, Source: "source1"},
|
||||
}, 0)
|
||||
|
||||
// Tests that a basic CSV document can be loaded as a single chunk.
|
||||
t.Run("basic case", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewCsvDataLoader(pkCols, pkSchema.Schema, ",", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Load all the data as a single chunk
|
||||
reader := bytes.NewReader([]byte("1,100,bar\n2,200,bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows := loadAllRows(ctx, t, dataLoader)
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
// Assert that the table contains the expected data
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a CSV record is split across two chunks of data, and the
|
||||
// partial record must be buffered and prepended to the next chunk.
|
||||
t.Run("record split across two chunks", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewCsvDataLoader(pkCols, pkSchema.Schema, ",", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("1,100,ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2,200,bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a CSV record is split across two chunks of data, and a
|
||||
// header row is present.
|
||||
t.Run("record split across two chunks, with header", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewCsvDataLoader(pkCols, pkSchema.Schema, ",", true)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("pk,c1,c2\n1,100,ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2,200,bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests a CSV record that contains a quoted newline character and is split
|
||||
// across two chunks.
|
||||
t.Run("quoted newlines across two chunks", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewCsvDataLoader(pkCols, pkSchema.Schema, ",", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("1,100,\"baz\nbar\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("bash\"\n2,200,bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "baz\nbar\nbash"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a PSV (i.e. delimiter='|') record is split across two chunks of data,
|
||||
// and a header row is present.
|
||||
t.Run("delimiter='|', record split across two chunks, with header", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewCsvDataLoader(pkCols, pkSchema.Schema, "|", true)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("pk|c1|c2\n1|100|ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2|200|bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
}
|
||||
|
||||
// loadAllRows loads all rows from the given DataLoader and returns them, failing the test if there are any errors.
|
||||
func loadAllRows(ctx *sql.Context, t *testing.T, d dataloader.DataLoader) []sql.Row {
|
||||
var rows []sql.Row
|
||||
iter, err := d.RowIter(ctx, nil)
|
||||
require.NoError(t, err)
|
||||
for {
|
||||
row, err := iter.Next(ctx)
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
// Copyright 2024 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package _dataloader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/doltgresql/core/dataloader"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// basicCsvData is used for a smoke test with CSV parsing
|
||||
const basicCsvData = `
|
||||
1,foo,bar
|
||||
2, ,bash
|
||||
`
|
||||
|
||||
// wrongNumberOfFieldsCsvData tests the case where records have different
|
||||
// numbers of values in them.
|
||||
const wrongNumberOfFieldsCsvData = `
|
||||
1,foo,bar,baz,bash
|
||||
2,blue
|
||||
3,boop,beep,bop,blorp
|
||||
`
|
||||
|
||||
// partialLineErrorCsvData tests the case where the last line of the CSV data
|
||||
// does not end with a newline character.
|
||||
const partialLineErrorCsvData = `
|
||||
1,foo,bar,baz,bash
|
||||
2,boop,beep,bop,blorp
|
||||
3,blue,g`
|
||||
|
||||
// nullAndEmptyStringQuotingCsvData tests the difference between representing
|
||||
// NULL and an empty string.
|
||||
const nullAndEmptyStringQuotingCsvData = `
|
||||
1,,NULL,"NULL",""
|
||||
`
|
||||
|
||||
// escapedQuotesCsvData tests escaped quotes in CSV data.
|
||||
const escapedQuotesCsvData = `
|
||||
1,'',"'","""",','''
|
||||
`
|
||||
|
||||
// newLineInQuotedFieldCsvData tests when a quoted field contains a newline.
|
||||
const newLineInQuotedFieldCsvData = `
|
||||
1,foo,"baz
|
||||
bar
|
||||
bash"
|
||||
`
|
||||
|
||||
// endOfDataMarkerCsvData tests when a quoted field contains the end of data marker.
|
||||
const endOfDataMarkerCsvData = `
|
||||
1,foo,"baz
|
||||
\.
|
||||
bash"
|
||||
`
|
||||
|
||||
// TestCsvReader tests various cases of CSV data parsing.
|
||||
func TestCsvReader(t *testing.T) {
|
||||
t.Run("basic CSV data", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(basicCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, "foo", row[1])
|
||||
assert.Equal(t, "bar", row[2])
|
||||
|
||||
// Read the second row
|
||||
row, err = csvReader.ReadSqlRow()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "2", row[0])
|
||||
assert.Equal(t, " ", row[1])
|
||||
assert.Equal(t, "bash", row[2])
|
||||
|
||||
// Read the EOF error
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Equal(t, io.EOF, err)
|
||||
})
|
||||
|
||||
t.Run("wrong number of fields", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(wrongNumberOfFieldsCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "1", row[0])
|
||||
require.Equal(t, "foo", row[1])
|
||||
require.Equal(t, "bar", row[2])
|
||||
require.Equal(t, "baz", row[3])
|
||||
require.Equal(t, "bash", row[4])
|
||||
|
||||
// Read the second row
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "record on line 3: wrong number of fields", err.Error())
|
||||
})
|
||||
|
||||
t.Run("incomplete line, no newline ending", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(partialLineErrorCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, "foo", row[1])
|
||||
assert.Equal(t, "bar", row[2])
|
||||
assert.Equal(t, "baz", row[3])
|
||||
assert.Equal(t, "bash", row[4])
|
||||
|
||||
// Read the second row
|
||||
row, err = csvReader.ReadSqlRow()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "2", row[0])
|
||||
assert.Equal(t, "boop", row[1])
|
||||
assert.Equal(t, "beep", row[2])
|
||||
assert.Equal(t, "bop", row[3])
|
||||
assert.Equal(t, "blorp", row[4])
|
||||
|
||||
// Third row should trigger a partialLineError
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Error(t, err)
|
||||
require.Equal(t, "incomplete record found at end of CSV data: 3,blue,g", err.Error())
|
||||
})
|
||||
|
||||
t.Run("null and empty string quoting", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(nullAndEmptyStringQuotingCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, nil, row[1])
|
||||
assert.Equal(t, "NULL", row[2])
|
||||
assert.Equal(t, "NULL", row[3])
|
||||
assert.Equal(t, "", row[4])
|
||||
|
||||
// Read the EOF error
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Equal(t, io.EOF, err)
|
||||
})
|
||||
|
||||
t.Run("quote escaping", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(escapedQuotesCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, "''", row[1])
|
||||
assert.Equal(t, "'", row[2])
|
||||
assert.Equal(t, "\"", row[3])
|
||||
assert.Equal(t, "'", row[4])
|
||||
assert.Equal(t, "'''", row[5])
|
||||
|
||||
// Read the EOF error
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Equal(t, io.EOF, err)
|
||||
})
|
||||
|
||||
t.Run("quoted newlines", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(newLineInQuotedFieldCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, "foo", row[1])
|
||||
assert.Equal(t, "baz\nbar\nbash", row[2])
|
||||
|
||||
// Read the EOF error
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Equal(t, io.EOF, err)
|
||||
})
|
||||
|
||||
t.Run("quoted end of data marker", func(t *testing.T) {
|
||||
csvReader, err := dataloader.NewCsvReader(newReader(endOfDataMarkerCsvData))
|
||||
require.NoError(t, err)
|
||||
|
||||
// Read the first row
|
||||
row, err := csvReader.ReadSqlRow()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "1", row[0])
|
||||
assert.Equal(t, "foo", row[1])
|
||||
assert.Equal(t, "baz\n\\.\nbash", row[2])
|
||||
|
||||
// Read the EOF error
|
||||
_, err = csvReader.ReadSqlRow()
|
||||
require.Equal(t, io.EOF, err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// testReader is a simple io.ReadCloser implementation that delegates reads to an io.Reader
|
||||
// and implements Close() as a no-op.
|
||||
type testReader struct {
|
||||
io.Reader
|
||||
}
|
||||
|
||||
var _ io.ReadCloser = (*testReader)(nil)
|
||||
|
||||
// Close implements the io.Closer interface
|
||||
func (frc *testReader) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// newReader returns an io.ReadCloser instance that reads the data from the specified
|
||||
// string |s| and is a no-op when Close() is called.
|
||||
func newReader(s string) io.ReadCloser {
|
||||
return &testReader{
|
||||
bytes.NewReader([]byte(s)),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright 2024 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package _dataloader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/doltgresql/core/dataloader"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestStringPrefixReader(t *testing.T) {
|
||||
t.Run("Read prefix and all data in single call", func(t *testing.T) {
|
||||
prefix := "prefix"
|
||||
reader := bytes.NewReader([]byte("0123456789"))
|
||||
prefixReader := dataloader.NewStringPrefixReader(prefix, reader)
|
||||
|
||||
data := make([]byte, 100)
|
||||
bytesRead, err := prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 16, bytesRead)
|
||||
require.Equal(t, "prefix0123456789", string(data[:bytesRead]))
|
||||
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.Equal(t, io.EOF, err)
|
||||
require.Equal(t, 0, bytesRead)
|
||||
})
|
||||
|
||||
t.Run("Read part of prefix", func(t *testing.T) {
|
||||
prefix := "prefix"
|
||||
reader := bytes.NewReader([]byte("0123456789"))
|
||||
prefixReader := dataloader.NewStringPrefixReader(prefix, reader)
|
||||
|
||||
data := make([]byte, 5)
|
||||
bytesRead, err := prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 5, bytesRead)
|
||||
require.Equal(t, "prefi", string(data[:bytesRead]))
|
||||
|
||||
// Read the next 5 bytes
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 5, bytesRead)
|
||||
require.Equal(t, "x0123", string(data[:bytesRead]))
|
||||
|
||||
// Read the next 5 bytes
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 5, bytesRead)
|
||||
require.Equal(t, "45678", string(data[:bytesRead]))
|
||||
|
||||
// Read the last byte
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, bytesRead)
|
||||
require.Equal(t, "9", string(data[:bytesRead]))
|
||||
|
||||
// Read EOF
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.Equal(t, io.EOF, err)
|
||||
require.Equal(t, 0, bytesRead)
|
||||
})
|
||||
|
||||
t.Run("Read to prefix boundary", func(t *testing.T) {
|
||||
prefix := "prefix"
|
||||
reader := bytes.NewReader([]byte("0123456789"))
|
||||
prefixReader := dataloader.NewStringPrefixReader(prefix, reader)
|
||||
|
||||
data := make([]byte, 6)
|
||||
bytesRead, err := prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 6, bytesRead)
|
||||
require.Equal(t, "prefix", string(data[:bytesRead]))
|
||||
|
||||
// Read the next 6 bytes
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 6, bytesRead)
|
||||
require.Equal(t, "012345", string(data[:bytesRead]))
|
||||
|
||||
// Read the next 6 bytes
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 4, bytesRead)
|
||||
require.Equal(t, "6789", string(data[:bytesRead]))
|
||||
|
||||
// Read EOF
|
||||
bytesRead, err = prefixReader.Read(data)
|
||||
require.Equal(t, io.EOF, err)
|
||||
require.Equal(t, 0, bytesRead)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
// Copyright 2024 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package _dataloader
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/memory"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/dolthub/doltgresql/core/dataloader"
|
||||
"github.com/dolthub/doltgresql/server/initialization"
|
||||
"github.com/dolthub/doltgresql/server/types"
|
||||
doltgresservercfg "github.com/dolthub/doltgresql/servercfg"
|
||||
)
|
||||
|
||||
func TestTabDataLoader(t *testing.T) {
|
||||
db := memory.NewDatabase("mydb")
|
||||
provider := memory.NewDBProvider(db)
|
||||
initialization.Initialize(nil, doltgresservercfg.DefaultServerConfig())
|
||||
|
||||
ctx := &sql.Context{
|
||||
Context: context.Background(),
|
||||
Session: memory.NewSession(sql.NewBaseSession(), provider),
|
||||
}
|
||||
|
||||
pkCols := []string{"pk", "c1", "c2"}
|
||||
pkSchema := sql.NewPrimaryKeySchema(sql.Schema{
|
||||
{Name: "pk", Type: types.Int64, Source: "source1"},
|
||||
{Name: "c1", Type: types.Int64, Source: "source1"},
|
||||
{Name: "c2", Type: types.VarChar, Source: "source1"},
|
||||
}, 0)
|
||||
|
||||
// Tests that a basic tab delimited doc can be loaded as a single chunk.
|
||||
t.Run("basic case", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewTabularDataLoader(pkCols, pkSchema.Schema, "\t", "\\N", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load all the data as a single chunk
|
||||
reader := bytes.NewReader([]byte("1\t100\tbar\n2\t200\tbash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a record is split across two chunks of data, and the
|
||||
// partial record must be buffered and prepended to the next chunk.
|
||||
t.Run("record split across two chunks", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewTabularDataLoader(pkCols, pkSchema.Schema, "\t", "\\N", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("1 100 ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2 200 bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a record is split across two chunks of data, and a
|
||||
// header row is present.
|
||||
t.Run("record split across two chunks, with header", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewTabularDataLoader(pkCols, pkSchema.Schema, "\t", "\\N", true)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("pk c1 c2\n1 100 ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2 200 bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
// Assert that the table contains the expected data
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests a record that contains a quoted newline character and is split
|
||||
// across two chunks.
|
||||
t.Run("quoted newlines across two chunks", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewTabularDataLoader(pkCols, pkSchema.Schema, "\t", "\\N", false)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("1 100 \"baz\\nbar\\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("bash\"\n2 200 bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
// Assert that the table contains the expected data
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "\"baz\\nbar\\nbash\""},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
|
||||
// Tests when a record is split across two chunks of data, and a
|
||||
// header row is present.
|
||||
t.Run("delimiter='|', record split across two chunks, with header", func(t *testing.T) {
|
||||
dataLoader, err := dataloader.NewTabularDataLoader(pkCols, pkSchema.Schema, "|", "\\N", true)
|
||||
require.NoError(t, err)
|
||||
|
||||
var rows []sql.Row
|
||||
|
||||
// Load the first chunk
|
||||
reader := bytes.NewReader([]byte("pk|c1|c2\n1|100|ba"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Load the second chunk
|
||||
reader = bytes.NewReader([]byte("r\n2|200|bash\n"))
|
||||
err = dataLoader.SetNextDataChunk(ctx, bufio.NewReader(reader))
|
||||
require.NoError(t, err)
|
||||
rows = append(rows, loadAllRows(ctx, t, dataLoader)...)
|
||||
|
||||
// Finish
|
||||
results, err := dataLoader.Finish(ctx)
|
||||
require.NoError(t, err)
|
||||
require.EqualValues(t, 2, results.RowsLoaded)
|
||||
|
||||
// Assert that the table contains the expected data
|
||||
assert.Equal(t, []sql.Row{
|
||||
{int64(1), int64(100), "bar"},
|
||||
{int64(2), int64(200), "bash"},
|
||||
}, rows)
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
// Copyright 2025 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package dumps
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/server"
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
"github.com/jackc/pgx/v5/pgproto3"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// ImportQueryError contains both a query and its associated error.
|
||||
type ImportQueryError struct {
|
||||
Query string
|
||||
Error string
|
||||
}
|
||||
|
||||
// InterceptArgs are the arguments that are passed to InterceptImportMessages.
|
||||
type InterceptArgs struct {
|
||||
DoltgresPort int
|
||||
SkippedQueries []string
|
||||
BreakpointQueries []string
|
||||
TriggerBreakpoint func(string)
|
||||
}
|
||||
|
||||
// passthroughArguments are the arguments that are passed to createPassthrough.
|
||||
type passthroughArguments struct {
|
||||
qeChan chan ImportQueryError
|
||||
terminate *sync.WaitGroup
|
||||
psqlConnBackend *pgproto3.Backend
|
||||
doltgresConnFrontend *pgproto3.Frontend
|
||||
triggerBreakpoint func(string)
|
||||
skippedQueries []string
|
||||
breakpointQueries []string
|
||||
}
|
||||
|
||||
// InterceptImportMessages sits between PSQL and Doltgres, returning all error messages that are encountered. As we rely
|
||||
// on PSQL to handle the import process, we normally wouldn't be able to associate error messages with queries, as this
|
||||
// information is not returned by PSQL itself. Therefore, we create our own connection to Doltgres, and a server that
|
||||
// PSQL listens to. We then forward everything from PSQL to Doltgres, while inspecting the messages as they come and go.
|
||||
func InterceptImportMessages(t *testing.T, args InterceptArgs) (int, chan ImportQueryError) {
|
||||
psqlPort, err := sql.GetEmptyPort()
|
||||
require.NoError(t, err)
|
||||
qeChan := make(chan ImportQueryError)
|
||||
listener, err := server.NewListener("tcp", fmt.Sprintf("127.0.0.1:%d", psqlPort), "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return psqlPort, qeChan
|
||||
}
|
||||
timer := time.NewTimer(5 * time.Second)
|
||||
timer.Stop()
|
||||
go func() {
|
||||
<-timer.C
|
||||
_ = listener.Close()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
psqlConn, err := listener.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
timer.Stop()
|
||||
terminate := &sync.WaitGroup{}
|
||||
terminate.Add(1)
|
||||
psqlConnBackend := pgproto3.NewBackend(psqlConn, psqlConn)
|
||||
doltgresConn, err := (&net.Dialer{}).Dial("tcp", fmt.Sprintf("127.0.0.1:%d", args.DoltgresPort))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
doltgresConnFrontend := pgproto3.NewFrontend(doltgresConn, doltgresConn)
|
||||
|
||||
if err = handleStartup(t, psqlConnBackend, doltgresConnFrontend, psqlConn); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
createPassthrough(passthroughArguments{
|
||||
qeChan: qeChan,
|
||||
terminate: terminate,
|
||||
psqlConnBackend: psqlConnBackend,
|
||||
doltgresConnFrontend: doltgresConnFrontend,
|
||||
triggerBreakpoint: args.TriggerBreakpoint,
|
||||
skippedQueries: args.SkippedQueries,
|
||||
breakpointQueries: args.BreakpointQueries,
|
||||
})
|
||||
terminate.Wait()
|
||||
_ = psqlConn.Close()
|
||||
_ = doltgresConn.Close()
|
||||
timer.Reset(5 * time.Second)
|
||||
}
|
||||
}()
|
||||
return psqlPort, qeChan
|
||||
}
|
||||
|
||||
// handleStartup handles the startup messages.
|
||||
func handleStartup(t *testing.T, psqlConnBackend *pgproto3.Backend, doltgresConnFrontend *pgproto3.Frontend, clientConn net.Conn) error {
|
||||
StartupLoop:
|
||||
for {
|
||||
startupMessage, err := psqlConnBackend.ReceiveStartupMessage()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch startupMessage := startupMessage.(type) {
|
||||
case *pgproto3.SSLRequest:
|
||||
if _, err = clientConn.Write([]byte{'N'}); err != nil {
|
||||
return err
|
||||
}
|
||||
case *pgproto3.StartupMessage:
|
||||
doltgresConnFrontend.Send(startupMessage)
|
||||
if err = doltgresConnFrontend.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
response, err := doltgresConnFrontend.Receive()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = setAuthType(psqlConnBackend, response); err != nil {
|
||||
return err
|
||||
}
|
||||
psqlConnBackend.Send(response)
|
||||
if err = psqlConnBackend.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
break StartupLoop
|
||||
case *pgproto3.GSSEncRequest:
|
||||
// we don't support GSSAPI
|
||||
_, err = clientConn.Write([]byte("N"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
t.Fatalf("unexpected startup message: %v", startupMessage)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// setAuthType sets the client's authentication type depending on the message received from the server. This is
|
||||
// necessary, as the client needs the proper context to know how to parse the returned messages.
|
||||
func setAuthType(clientConnBackend *pgproto3.Backend, message pgproto3.BackendMessage) error {
|
||||
switch message.(type) {
|
||||
case *pgproto3.AuthenticationOk:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeOk)
|
||||
case *pgproto3.AuthenticationCleartextPassword:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeCleartextPassword)
|
||||
case *pgproto3.AuthenticationMD5Password:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeMD5Password)
|
||||
case *pgproto3.AuthenticationGSS:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeGSS)
|
||||
case *pgproto3.AuthenticationGSSContinue:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeGSSCont)
|
||||
case *pgproto3.AuthenticationSASL:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeSASL)
|
||||
case *pgproto3.AuthenticationSASLContinue:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeSASLContinue)
|
||||
case *pgproto3.AuthenticationSASLFinal:
|
||||
return clientConnBackend.SetAuthType(pgproto3.AuthTypeSASLFinal)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// createPassthrough creates the go routines that will read from and write to the connections.
|
||||
func createPassthrough(args passthroughArguments) {
|
||||
lastQuery := ""
|
||||
writeMutex := &sync.Mutex{}
|
||||
go func() {
|
||||
defer args.terminate.Done()
|
||||
for {
|
||||
psqlMessage, err := args.psqlConnBackend.Receive()
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
if errStr != "unexpected EOF" && !strings.HasSuffix(errStr, "use of closed network connection") {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
switch msg := psqlMessage.(type) {
|
||||
case *pgproto3.Query:
|
||||
writeMutex.Lock()
|
||||
if len(lastQuery) == 0 {
|
||||
lastQuery = msg.String
|
||||
}
|
||||
writeMutex.Unlock()
|
||||
for _, query := range args.skippedQueries {
|
||||
if strings.HasPrefix(msg.String, query) {
|
||||
// An empty query allows for the proper response messages to be sent.
|
||||
msg.String = ";"
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, query := range args.breakpointQueries {
|
||||
if strings.HasPrefix(msg.String, query) {
|
||||
args.triggerBreakpoint(msg.String)
|
||||
break
|
||||
}
|
||||
}
|
||||
case *pgproto3.Terminate:
|
||||
return
|
||||
}
|
||||
args.doltgresConnFrontend.Send(psqlMessage)
|
||||
if err = args.doltgresConnFrontend.Flush(); err != nil {
|
||||
errStr := err.Error()
|
||||
if errStr != "unexpected EOF" && !strings.HasSuffix(errStr, "use of closed network connection") {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
for {
|
||||
doltgresMessage, err := args.doltgresConnFrontend.Receive()
|
||||
if err != nil {
|
||||
errStr := err.Error()
|
||||
if errStr != "unexpected EOF" &&
|
||||
!strings.HasSuffix(errStr, "use of closed network connection") &&
|
||||
!strings.HasSuffix(errStr, "An existing connection was forcibly closed by the remote host.") {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
switch msg := doltgresMessage.(type) {
|
||||
case *pgproto3.ErrorResponse:
|
||||
writeMutex.Lock()
|
||||
if len(lastQuery) == 0 {
|
||||
args.qeChan <- ImportQueryError{
|
||||
Query: "UNKNOWN QUERY HAS ERRORED",
|
||||
Error: msg.Message,
|
||||
}
|
||||
} else {
|
||||
args.qeChan <- ImportQueryError{
|
||||
Query: lastQuery,
|
||||
Error: msg.Message,
|
||||
}
|
||||
}
|
||||
writeMutex.Unlock()
|
||||
case *pgproto3.ReadyForQuery:
|
||||
writeMutex.Lock()
|
||||
lastQuery = ""
|
||||
writeMutex.Unlock()
|
||||
default:
|
||||
if err = setAuthType(args.psqlConnBackend, doltgresMessage); err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
args.psqlConnBackend.Send(doltgresMessage)
|
||||
if err = args.psqlConnBackend.Flush(); err != nil {
|
||||
errStr := err.Error()
|
||||
if errStr != "unexpected EOF" &&
|
||||
!strings.HasSuffix(errStr, "use of closed network connection") &&
|
||||
!strings.HasSuffix(errStr, "An existing connection was forcibly closed by the remote host.") {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
// Copyright 2025 Dolthub, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
query = `extension:sql pg_dump`
|
||||
downloadCount = 110
|
||||
)
|
||||
|
||||
// RepoName simply contains the name of the repository.
|
||||
type RepoName struct {
|
||||
FullName string `json:"full_name"`
|
||||
}
|
||||
|
||||
// Item is a SQL file (hopefully) containing a pg_dump.
|
||||
type Item struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
HtmlURL string `json:"html_url"`
|
||||
ContentsURL string `json:"url"`
|
||||
Repository RepoName `json:"repository"`
|
||||
}
|
||||
|
||||
// CodeSearchResult contains the result of a code search.
|
||||
type CodeSearchResult struct {
|
||||
TotalCount int `json:"total_count"`
|
||||
IncompleteResults bool `json:"incomplete_results"`
|
||||
Items []Item `json:"items"`
|
||||
Message string `json:"message"` // Only used when there's an error
|
||||
}
|
||||
|
||||
// ContentFile is all of the information about a SQL file, including how to retrieve it.
|
||||
type ContentFile struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
SHA string `json:"sha"`
|
||||
Size int64 `json:"size"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
DownloadURL string `json:"download_url"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
httpClient := &http.Client{Timeout: 30 * time.Second}
|
||||
token := os.Getenv("GITHUB_TOKEN")
|
||||
if len(token) == 0 {
|
||||
fmt.Println("Must provide a GITHUB_TOKEN as an environment variable")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, currentFileLocation, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
fmt.Println("Unable to find the folder where this file is located")
|
||||
os.Exit(1)
|
||||
}
|
||||
dumpsFolder := filepath.Clean(filepath.Join(filepath.Dir(currentFileLocation), "../sql"))
|
||||
|
||||
var saved int
|
||||
page := 1
|
||||
|
||||
OuterLoop:
|
||||
for {
|
||||
remaining := downloadCount - saved
|
||||
items, err := SearchCode(ctx, httpClient, token, page, min(50, remaining))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if len(items) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
cf, err := GetContent(ctx, httpClient, token, item.ContentsURL)
|
||||
if err != nil {
|
||||
fmt.Printf("warn: %s/%s: %v\n", item.Repository.FullName, item.Path, err)
|
||||
continue
|
||||
}
|
||||
if cf.Type != "file" || cf.DownloadURL == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
dest := filepath.Join(dumpsFolder, SanitizePath(item.Repository.FullName)+filepath.Ext(cf.Path))
|
||||
if _, err = os.Stat(dest); err == nil {
|
||||
continue
|
||||
}
|
||||
if err = DownloadFile(ctx, httpClient, item, cf.DownloadURL, dest); err != nil {
|
||||
fmt.Printf("download error: %s -> %v\n", dest, err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("saved: %s (%d bytes)\n", dest, cf.Size)
|
||||
|
||||
saved++
|
||||
if saved >= downloadCount {
|
||||
break OuterLoop
|
||||
}
|
||||
time.Sleep(6500 * time.Millisecond) // We sleep to mitigate rate limits
|
||||
}
|
||||
page++
|
||||
}
|
||||
}
|
||||
|
||||
// SearchCode executes the query against the API, returning all items that were found.
|
||||
func SearchCode(ctx context.Context, hc *http.Client, token string, page int, perPage int) ([]Item, error) {
|
||||
params := url.Values{}
|
||||
params.Set("q", query)
|
||||
params.Set("page", strconv.Itoa(page))
|
||||
params.Set("per_page", strconv.Itoa(perPage))
|
||||
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", "https://api.github.com/search/code?"+params.Encode(), nil)
|
||||
SetHeaders(req, token)
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if HandleRate(resp) {
|
||||
return SearchCode(ctx, hc, token, page, perPage)
|
||||
}
|
||||
var sr CodeSearchResult
|
||||
if err = json.NewDecoder(resp.Body).Decode(&sr); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
if sr.Message != "" {
|
||||
return nil, fmt.Errorf("search error: %s (HTTP %d)", sr.Message, resp.StatusCode)
|
||||
}
|
||||
return nil, fmt.Errorf("search error: HTTP %d", resp.StatusCode)
|
||||
}
|
||||
return sr.Items, nil
|
||||
}
|
||||
|
||||
// GetContent gets the ContentFile from the given URL.
|
||||
func GetContent(ctx context.Context, hc *http.Client, token string, contentsURL string) (*ContentFile, error) {
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", contentsURL, nil)
|
||||
SetHeaders(req, token)
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if HandleRate(resp) {
|
||||
return GetContent(ctx, hc, token, contentsURL)
|
||||
}
|
||||
if resp.StatusCode != 200 {
|
||||
b, _ := io.ReadAll(resp.Body)
|
||||
return nil, fmt.Errorf("contents error: HTTP %d: %s", resp.StatusCode, strings.TrimSpace(string(b)))
|
||||
}
|
||||
var cf ContentFile
|
||||
if err = json.NewDecoder(resp.Body).Decode(&cf); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cf, nil
|
||||
}
|
||||
|
||||
// DownloadFile downloads the given SQL file to the destination.
|
||||
func DownloadFile(ctx context.Context, hc *http.Client, item Item, rawURL string, dest string) error {
|
||||
req, _ := http.NewRequestWithContext(ctx, "GET", rawURL, nil)
|
||||
req.Header.Set("User-Agent", "gh-pg-dump-finder/1.0")
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("download HTTP %d", resp.StatusCode)
|
||||
}
|
||||
out, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
_, _ = io.WriteString(out, fmt.Sprintf("-- Downloaded from: %s\n", item.HtmlURL))
|
||||
_, err = io.Copy(out, resp.Body)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetHeaders sets the appropriate headers for a request.
|
||||
func SetHeaders(req *http.Request, token string) {
|
||||
req.Header.Set("Accept", "application/vnd.github.v3+json")
|
||||
req.Header.Set("User-Agent", "gh-pg-dump-finder/1.0")
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
}
|
||||
|
||||
// HandleRate handles potential rate limits.
|
||||
func HandleRate(resp *http.Response) bool {
|
||||
if resp.StatusCode == 403 {
|
||||
if ra := resp.Header.Get("Retry-After"); ra != "" {
|
||||
if secs, _ := strconv.Atoi(ra); secs > 0 {
|
||||
sleepTime := time.Duration(secs) * time.Second
|
||||
fmt.Printf("rate limited (%s), retrying\n", sleepTime.String())
|
||||
time.Sleep(sleepTime)
|
||||
return true
|
||||
}
|
||||
}
|
||||
if reset := resp.Header.Get("X-RateLimit-Reset"); reset != "" {
|
||||
if ts, _ := strconv.ParseInt(reset, 10, 64); ts > 0 {
|
||||
wait := time.Until(time.Unix(ts+5, 0))
|
||||
if wait > 0 && wait < 5*time.Minute {
|
||||
fmt.Printf("rate limited (%s), retrying\n", wait.String())
|
||||
time.Sleep(wait)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SanitizePath removes potentially invalid file system characters.
|
||||
func SanitizePath(s string) string {
|
||||
illegal := `<>:"\|/?*`
|
||||
for _, r := range illegal {
|
||||
s = strings.ReplaceAll(s, string(r), "_")
|
||||
}
|
||||
return s
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
-- Downloaded from: https://github.com/A-lang209/Salon-Appointment-Scheduler/blob/65664c1eca91624676853a6b56a8db25e807ed7c/salon.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
|
||||
-- Dumped by pg_dump version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
DROP DATABASE salon;
|
||||
--
|
||||
-- Name: salon; Type: DATABASE; Schema: -; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE DATABASE salon WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';
|
||||
|
||||
|
||||
ALTER DATABASE salon OWNER TO freecodecamp;
|
||||
|
||||
\connect salon
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: appointments; Type: TABLE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE TABLE public.appointments (
|
||||
appointment_id integer NOT NULL,
|
||||
"time" character varying(255),
|
||||
service_id integer,
|
||||
customer_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.appointments OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: appointments_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.appointments_appointment_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.appointments_appointment_id_seq OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: appointments_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.appointments_appointment_id_seq OWNED BY public.appointments.appointment_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: customers; Type: TABLE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE TABLE public.customers (
|
||||
customer_id integer NOT NULL,
|
||||
phone character varying(30),
|
||||
name character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.customers OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.customers_customer_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.customers_customer_id_seq OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: customers_customer_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.customers_customer_id_seq OWNED BY public.customers.customer_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: services; Type: TABLE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE TABLE public.services (
|
||||
service_id integer NOT NULL,
|
||||
name character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.services OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.services_service_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.services_service_id_seq OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointments appointment_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointments ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointments_appointment_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: customers customer_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.customers ALTER COLUMN customer_id SET DEFAULT nextval('public.customers_customer_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: appointments; Type: TABLE DATA; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: customers; Type: TABLE DATA; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: services; Type: TABLE DATA; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
INSERT INTO public.services VALUES (1, 'Haircut');
|
||||
INSERT INTO public.services VALUES (2, 'Shave');
|
||||
INSERT INTO public.services VALUES (3, 'Pedicure');
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointments_appointment_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.appointments_appointment_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.customers_customer_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: services_service_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.services_service_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointments appointments_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointments
|
||||
ADD CONSTRAINT appointments_pkey PRIMARY KEY (appointment_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: customers customers_phone_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.customers
|
||||
ADD CONSTRAINT customers_phone_key UNIQUE (phone);
|
||||
|
||||
|
||||
--
|
||||
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.customers
|
||||
ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.services
|
||||
ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointments appointment_customer; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointments
|
||||
ADD CONSTRAINT appointment_customer FOREIGN KEY (customer_id) REFERENCES public.customers(customer_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointments appointment_service; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointments
|
||||
ADD CONSTRAINT appointment_service FOREIGN KEY (service_id) REFERENCES public.services(service_id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,887 @@
|
||||
-- Downloaded from: https://github.com/AlexTransit/venderctl/blob/5a4426d96e78edbf76b8157e42af2508dc7449bd/sql/db.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 11.15 (Debian 11.15-1.pgdg110+1)
|
||||
-- Dumped by pg_dump version 11.1
|
||||
|
||||
-- Started on 2022-04-27 18:41:37
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
ALTER TABLE IF EXISTS ONLY public.trans DROP CONSTRAINT IF EXISTS trans_tax_job_id_fkey;
|
||||
DROP TRIGGER IF EXISTS trans_tax ON public.trans;
|
||||
DROP TRIGGER IF EXISTS tax_job_modified ON public.tax_job;
|
||||
DROP TRIGGER IF EXISTS tax_job_maint_before ON public.tax_job;
|
||||
DROP TRIGGER IF EXISTS tax_job_maint_after ON public.tax_job;
|
||||
DROP INDEX IF EXISTS public.trans_executer;
|
||||
DROP INDEX IF EXISTS public.tgchat_idx2;
|
||||
DROP INDEX IF EXISTS public.tgchat_idx1;
|
||||
DROP INDEX IF EXISTS public.tgchat_idx;
|
||||
DROP INDEX IF EXISTS public.idx_trans_vmtime;
|
||||
DROP INDEX IF EXISTS public.idx_trans_vmid_vmtime;
|
||||
DROP INDEX IF EXISTS public.idx_tax_job_sched;
|
||||
DROP INDEX IF EXISTS public.idx_tax_job_help;
|
||||
DROP INDEX IF EXISTS public.idx_state_vmid_state_received;
|
||||
DROP INDEX IF EXISTS public.idx_inventory_vmid_service;
|
||||
DROP INDEX IF EXISTS public.idx_inventory_vmid_not_service;
|
||||
DROP INDEX IF EXISTS public.idx_ingest_received;
|
||||
DROP INDEX IF EXISTS public.idx_error_vmid_vmtime_code;
|
||||
DROP INDEX IF EXISTS public.idx_catalog_vmid_code_name;
|
||||
DROP INDEX IF EXISTS public.cashless_vmid_payment_id_order_id_key;
|
||||
DROP INDEX IF EXISTS public.cashless_idx;
|
||||
ALTER TABLE IF EXISTS ONLY public.tg_user DROP CONSTRAINT IF EXISTS tg_user_pkey;
|
||||
ALTER TABLE IF EXISTS ONLY public.tax_job DROP CONSTRAINT IF EXISTS tax_job_pkey;
|
||||
ALTER TABLE IF EXISTS ONLY public.state DROP CONSTRAINT IF EXISTS state_vmid_key;
|
||||
ALTER TABLE IF EXISTS ONLY public.robot DROP CONSTRAINT IF EXISTS robot_serial_num_key;
|
||||
ALTER TABLE IF EXISTS ONLY public.robot DROP CONSTRAINT IF EXISTS "robot-key";
|
||||
ALTER TABLE IF EXISTS public.tax_job ALTER COLUMN id DROP DEFAULT;
|
||||
DROP SEQUENCE IF EXISTS public.tg_user_user_id_seq;
|
||||
DROP TABLE IF EXISTS public.tg_user;
|
||||
DROP TABLE IF EXISTS public.tg_chat;
|
||||
DROP SEQUENCE IF EXISTS public.tax_job_id_seq;
|
||||
DROP VIEW IF EXISTS public.tax_job_help;
|
||||
DROP TABLE IF EXISTS public.state;
|
||||
DROP TABLE IF EXISTS public.robot;
|
||||
DROP TABLE IF EXISTS public.old_state;
|
||||
DROP TABLE IF EXISTS public.inventory;
|
||||
DROP TABLE IF EXISTS public.ingest;
|
||||
DROP TABLE IF EXISTS public.error;
|
||||
DROP TABLE IF EXISTS public.catalog;
|
||||
DROP TABLE IF EXISTS public.cashless;
|
||||
DROP FUNCTION IF EXISTS public.vmstate(s integer);
|
||||
DROP FUNCTION IF EXISTS public.trans_tax_trigger();
|
||||
DROP FUNCTION IF EXISTS public.tax_job_trans(t public.trans);
|
||||
DROP TABLE IF EXISTS public.trans;
|
||||
DROP FUNCTION IF EXISTS public.tax_job_take(arg_worker text);
|
||||
DROP TABLE IF EXISTS public.tax_job;
|
||||
DROP FUNCTION IF EXISTS public.tax_job_modified();
|
||||
DROP FUNCTION IF EXISTS public.tax_job_maint_before();
|
||||
DROP FUNCTION IF EXISTS public.tax_job_maint_after();
|
||||
DROP FUNCTION IF EXISTS public.state_update(arg_vmid integer, arg_state integer);
|
||||
DROP FUNCTION IF EXISTS public.connect_update(arg_vmid integer, arg_connect boolean);
|
||||
DROP TYPE IF EXISTS public.tax_job_state;
|
||||
DROP TYPE IF EXISTS public.cashless_state;
|
||||
DROP EXTENSION IF EXISTS hstore;
|
||||
--
|
||||
-- TOC entry 2 (class 3079 OID 24642)
|
||||
-- Name: hstore; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS hstore WITH SCHEMA public;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3092 (class 0 OID 0)
|
||||
-- Dependencies: 2
|
||||
-- Name: EXTENSION hstore; Type: COMMENT; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION hstore IS 'data type for storing sets of (key, value) pairs';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 692 (class 1247 OID 65591)
|
||||
-- Name: cashless_state; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE public.cashless_state AS ENUM (
|
||||
'order_start',
|
||||
'order_prepay',
|
||||
'order_complete',
|
||||
'order_cancel'
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 707 (class 1247 OID 26134)
|
||||
-- Name: tax_job_state; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE public.tax_job_state AS ENUM (
|
||||
'sched',
|
||||
'busy',
|
||||
'final',
|
||||
'help'
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 294 (class 1255 OID 55071)
|
||||
-- Name: connect_update(integer, boolean); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.connect_update(arg_vmid integer, arg_connect boolean) RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
BEGIN
|
||||
INSERT INTO state (vmid, state, received, connected, contime) VALUES (arg_vmid, 0, CURRENT_TIMESTAMP, arg_connect, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (vmid) DO UPDATE
|
||||
SET connected = excluded.connected, contime = CURRENT_TIMESTAMP;
|
||||
return null;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 290 (class 1255 OID 25797)
|
||||
-- Name: state_update(integer, integer); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.state_update(arg_vmid integer, arg_state integer) RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
DECLARE
|
||||
old_state int4 = NULL;
|
||||
BEGIN
|
||||
SELECT
|
||||
state INTO old_state
|
||||
FROM
|
||||
state
|
||||
WHERE
|
||||
vmid = arg_vmid
|
||||
LIMIT 1
|
||||
FOR UPDATE;
|
||||
INSERT INTO state (vmid, state, received)
|
||||
VALUES (arg_vmid, arg_state, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT (vmid)
|
||||
DO UPDATE SET
|
||||
state = excluded.state, received = excluded.received;
|
||||
RETURN old_state;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 291 (class 1255 OID 26171)
|
||||
-- Name: tax_job_maint_after(); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.tax_job_maint_after() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
BEGIN
|
||||
CASE new.state
|
||||
WHEN ''final'' THEN
|
||||
NOTIFY tax_job_final;
|
||||
WHEN ''help'' THEN
|
||||
NOTIFY tax_job_help;
|
||||
WHEN ''sched'' THEN
|
||||
NOTIFY tax_job_sched;
|
||||
ELSE
|
||||
NULL;
|
||||
END CASE;
|
||||
RETURN NEW;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 292 (class 1255 OID 26173)
|
||||
-- Name: tax_job_maint_before(); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.tax_job_maint_before() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
BEGIN
|
||||
IF new.state = ''final'' THEN
|
||||
new.scheduled = NULL;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 293 (class 1255 OID 26175)
|
||||
-- Name: tax_job_modified(); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.tax_job_modified() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
BEGIN
|
||||
new.modified := CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- TOC entry 209 (class 1259 OID 26219)
|
||||
-- Name: tax_job; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.tax_job (
|
||||
id bigint NOT NULL,
|
||||
state public.tax_job_state NOT NULL,
|
||||
created timestamp with time zone NOT NULL,
|
||||
modified timestamp with time zone NOT NULL,
|
||||
scheduled timestamp with time zone,
|
||||
worker text,
|
||||
processor text,
|
||||
ext_id text,
|
||||
data jsonb,
|
||||
gross integer,
|
||||
notes text[],
|
||||
ops jsonb,
|
||||
CONSTRAINT tax_job_check CHECK ((NOT ((state = 'sched'::public.tax_job_state) AND (scheduled IS NULL)))),
|
||||
CONSTRAINT tax_job_check1 CHECK ((NOT ((state = 'busy'::public.tax_job_state) AND (worker IS NULL))))
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 295 (class 1255 OID 26249)
|
||||
-- Name: tax_job_take(text); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.tax_job_take(arg_worker text) RETURNS SETOF public.tax_job
|
||||
LANGUAGE sql
|
||||
AS '
|
||||
UPDATE
|
||||
tax_job
|
||||
SET
|
||||
state = ''busy'',
|
||||
worker = arg_worker
|
||||
WHERE
|
||||
state = ''sched''
|
||||
AND scheduled <= CURRENT_TIMESTAMP
|
||||
AND id = (
|
||||
SELECT
|
||||
id
|
||||
FROM
|
||||
tax_job
|
||||
WHERE
|
||||
state = ''sched''
|
||||
AND scheduled <= CURRENT_TIMESTAMP
|
||||
ORDER BY
|
||||
scheduled,
|
||||
modified
|
||||
LIMIT 1
|
||||
FOR UPDATE
|
||||
SKIP LOCKED)
|
||||
RETURNING
|
||||
*;
|
||||
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 210 (class 1259 OID 26232)
|
||||
-- Name: trans; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.trans (
|
||||
vmid integer NOT NULL,
|
||||
vmtime timestamp with time zone,
|
||||
received timestamp with time zone NOT NULL,
|
||||
menu_code text NOT NULL,
|
||||
options integer[],
|
||||
price integer NOT NULL,
|
||||
method integer NOT NULL,
|
||||
tax_job_id bigint,
|
||||
executer bigint,
|
||||
exeputer_type integer,
|
||||
executer_str text
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 296 (class 1255 OID 26250)
|
||||
-- Name: tax_job_trans(public.trans); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.tax_job_trans(t public.trans) RETURNS public.tax_job
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
# print_strict_params ON
|
||||
DECLARE
|
||||
tjd jsonb;
|
||||
ops jsonb;
|
||||
tj tax_job;
|
||||
name text;
|
||||
BEGIN
|
||||
-- lock trans row
|
||||
PERFORM
|
||||
1
|
||||
FROM
|
||||
trans
|
||||
WHERE (vmid, vmtime) = (t.vmid,
|
||||
t.vmtime)
|
||||
LIMIT 1
|
||||
FOR UPDATE;
|
||||
-- if trans already has tax_job assigned, just return it
|
||||
IF t.tax_job_id IS NOT NULL THEN
|
||||
SELECT
|
||||
* INTO STRICT tj
|
||||
FROM
|
||||
tax_job
|
||||
WHERE
|
||||
id = t.tax_job_id;
|
||||
RETURN tj;
|
||||
END IF;
|
||||
-- op code to human friendly name via catalog
|
||||
SELECT
|
||||
catalog.name INTO name
|
||||
FROM
|
||||
catalog
|
||||
WHERE (vmid, code) = (t.vmid,
|
||||
t.menu_code);
|
||||
IF NOT found THEN
|
||||
name := ''#'' || t.menu_code;
|
||||
END IF;
|
||||
ops := jsonb_build_array (jsonb_build_object(''vmid'', t.vmid, ''time'', t.vmtime, ''name'', name, ''code'', t.menu_code, ''amount'', 1, ''price'', t.price, ''method'', t.method));
|
||||
INSERT INTO tax_job (state, created, modified, scheduled, processor, ops, gross)
|
||||
VALUES (''sched'', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ''ru2019'', ops, t.price)
|
||||
RETURNING
|
||||
* INTO STRICT tj;
|
||||
UPDATE
|
||||
trans
|
||||
SET
|
||||
tax_job_id = tj.id
|
||||
WHERE (vmid, vmtime) = (t.vmid,
|
||||
t.vmtime);
|
||||
RETURN tj;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 289 (class 1255 OID 26177)
|
||||
-- Name: trans_tax_trigger(); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.trans_tax_trigger() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS '
|
||||
BEGIN
|
||||
IF (NEW.vmid = (SELECT vmid from robot where robot.vmid = NEW.vmid and robot.work = TRUE) and (NEW.method = 1 or NEW.method = 2)) THEN
|
||||
PERFORM
|
||||
tax_job_trans (new);
|
||||
END IF;
|
||||
RETURN new;
|
||||
END;
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 297 (class 1255 OID 26492)
|
||||
-- Name: vmstate(integer); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.vmstate(s integer) RETURNS text
|
||||
LANGUAGE sql IMMUTABLE STRICT
|
||||
AS '
|
||||
-- TODO generate from tele.proto
|
||||
-- Invalid = 0;
|
||||
-- Boot = 1;
|
||||
-- Nominal = 2;
|
||||
-- Disconnected = 3;
|
||||
-- Problem = 4;
|
||||
-- Service = 5;
|
||||
-- Lock = 6;
|
||||
SELECT
|
||||
CASE WHEN s = 0 THEN
|
||||
''Invalid''
|
||||
WHEN s = 1 THEN
|
||||
''Boot''
|
||||
WHEN s = 2 THEN
|
||||
''Nominal''
|
||||
WHEN s = 3 THEN
|
||||
''Disconnected''
|
||||
WHEN s = 4 THEN
|
||||
''Problem''
|
||||
WHEN s = 5 THEN
|
||||
''Service''
|
||||
WHEN s = 6 THEN
|
||||
''Lock''
|
||||
ELSE
|
||||
''unknown:'' || s
|
||||
END
|
||||
';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 65639)
|
||||
-- Name: cashless; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.cashless (
|
||||
state public.cashless_state DEFAULT 'order_start'::public.cashless_state NOT NULL,
|
||||
vmid integer NOT NULL,
|
||||
create_date timestamp with time zone NOT NULL,
|
||||
credit_date timestamp with time zone,
|
||||
finish_date timestamp with time zone,
|
||||
payment_id character varying(20) NOT NULL,
|
||||
order_id character varying NOT NULL,
|
||||
amount integer NOT NULL,
|
||||
credited integer DEFAULT 0 NOT NULL,
|
||||
bank_commission integer DEFAULT 0 NOT NULL,
|
||||
terminal text
|
||||
);
|
||||
ALTER TABLE ONLY public.cashless ALTER COLUMN credit_date SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.cashless ALTER COLUMN payment_id SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.cashless ALTER COLUMN credited SET STATISTICS 0;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 212 (class 1259 OID 26503)
|
||||
-- Name: catalog; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.catalog (
|
||||
vmid integer NOT NULL,
|
||||
code text NOT NULL,
|
||||
name text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 206 (class 1259 OID 25437)
|
||||
-- Name: error; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.error (
|
||||
vmid integer NOT NULL,
|
||||
vmtime timestamp with time zone NOT NULL,
|
||||
received timestamp with time zone NOT NULL,
|
||||
code integer,
|
||||
message text NOT NULL,
|
||||
count integer,
|
||||
app_version text
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 205 (class 1259 OID 25417)
|
||||
-- Name: ingest; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.ingest (
|
||||
received timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
vmid integer NOT NULL,
|
||||
done boolean DEFAULT false NOT NULL,
|
||||
raw bytea NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 207 (class 1259 OID 25482)
|
||||
-- Name: inventory; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.inventory (
|
||||
vmid integer NOT NULL,
|
||||
at_service boolean NOT NULL,
|
||||
vmtime timestamp with time zone NOT NULL,
|
||||
received timestamp with time zone NOT NULL,
|
||||
inventory public.hstore,
|
||||
cashbox_bill public.hstore,
|
||||
cashbox_coin public.hstore,
|
||||
change_bill public.hstore,
|
||||
change_coin public.hstore
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 214 (class 1259 OID 55050)
|
||||
-- Name: old_state; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.old_state (
|
||||
state integer
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 213 (class 1259 OID 26578)
|
||||
-- Name: robot; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.robot (
|
||||
vmid integer NOT NULL,
|
||||
vmnum integer NOT NULL,
|
||||
description text,
|
||||
location text,
|
||||
bunkers public.hstore,
|
||||
"mobile-number" numeric(10,0),
|
||||
serial_num numeric(7,0) NOT NULL,
|
||||
work boolean DEFAULT true NOT NULL,
|
||||
in_robo public.hstore,
|
||||
to_robo public.hstore
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3093 (class 0 OID 0)
|
||||
-- Dependencies: 213
|
||||
-- Name: COLUMN robot.in_robo; Type: COMMENT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
COMMENT ON COLUMN public.robot.in_robo IS 'inventoiry inside robo';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 215 (class 1259 OID 55059)
|
||||
-- Name: state; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.state (
|
||||
vmid integer NOT NULL,
|
||||
state integer NOT NULL,
|
||||
received timestamp with time zone NOT NULL,
|
||||
connected boolean DEFAULT false NOT NULL,
|
||||
contime timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 211 (class 1259 OID 26245)
|
||||
-- Name: tax_job_help; Type: VIEW; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE VIEW public.tax_job_help AS
|
||||
SELECT tax_job.id,
|
||||
tax_job.state,
|
||||
tax_job.created,
|
||||
tax_job.modified,
|
||||
tax_job.scheduled,
|
||||
tax_job.worker,
|
||||
tax_job.processor,
|
||||
tax_job.ext_id,
|
||||
tax_job.data,
|
||||
tax_job.gross,
|
||||
tax_job.notes
|
||||
FROM public.tax_job
|
||||
WHERE (tax_job.state = 'help'::public.tax_job_state)
|
||||
ORDER BY tax_job.modified;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 208 (class 1259 OID 26217)
|
||||
-- Name: tax_job_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.tax_job_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3094 (class 0 OID 0)
|
||||
-- Dependencies: 208
|
||||
-- Name: tax_job_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.tax_job_id_seq OWNED BY public.tax_job.id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 65014)
|
||||
-- Name: tg_chat; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.tg_chat (
|
||||
create_date timestamp(0) without time zone DEFAULT now() NOT NULL,
|
||||
messageid integer NOT NULL,
|
||||
fromid bigint NOT NULL,
|
||||
toid bigint NOT NULL,
|
||||
date integer NOT NULL,
|
||||
text text,
|
||||
changedate integer,
|
||||
changetext text
|
||||
);
|
||||
ALTER TABLE ONLY public.tg_chat ALTER COLUMN messageid SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.tg_chat ALTER COLUMN fromid SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.tg_chat ALTER COLUMN toid SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.tg_chat ALTER COLUMN text SET STATISTICS 0;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 64971)
|
||||
-- Name: tg_user; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.tg_user (
|
||||
ban boolean DEFAULT false,
|
||||
userid bigint NOT NULL,
|
||||
name text,
|
||||
firstname text,
|
||||
lastname text,
|
||||
phonenumber text,
|
||||
balance integer,
|
||||
credit integer,
|
||||
registerdate integer,
|
||||
diskont integer DEFAULT 3
|
||||
);
|
||||
ALTER TABLE ONLY public.tg_user ALTER COLUMN name SET STATISTICS 0;
|
||||
ALTER TABLE ONLY public.tg_user ALTER COLUMN phonenumber SET STATISTICS 0;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 216 (class 1259 OID 64969)
|
||||
-- Name: tg_user_user_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.tg_user_user_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3095 (class 0 OID 0)
|
||||
-- Dependencies: 216
|
||||
-- Name: tg_user_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.tg_user_user_id_seq OWNED BY public.tg_user.userid;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2922 (class 2604 OID 26222)
|
||||
-- Name: tax_job id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tax_job ALTER COLUMN id SET DEFAULT nextval('public.tax_job_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2947 (class 2606 OID 26586)
|
||||
-- Name: robot robot-key; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.robot
|
||||
ADD CONSTRAINT "robot-key" PRIMARY KEY (vmid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2949 (class 2606 OID 26588)
|
||||
-- Name: robot robot_serial_num_key; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.robot
|
||||
ADD CONSTRAINT robot_serial_num_key UNIQUE (serial_num);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2952 (class 2606 OID 55075)
|
||||
-- Name: state state_vmid_key; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.state
|
||||
ADD CONSTRAINT state_vmid_key UNIQUE (vmid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2941 (class 2606 OID 26229)
|
||||
-- Name: tax_job tax_job_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tax_job
|
||||
ADD CONSTRAINT tax_job_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2954 (class 2606 OID 64984)
|
||||
-- Name: tg_user tg_user_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.tg_user
|
||||
ADD CONSTRAINT tg_user_pkey PRIMARY KEY (userid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2958 (class 1259 OID 65648)
|
||||
-- Name: cashless_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX cashless_idx ON public.cashless USING btree (payment_id, order_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2959 (class 1259 OID 65649)
|
||||
-- Name: cashless_vmid_payment_id_order_id_key; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX cashless_vmid_payment_id_order_id_key ON public.cashless USING btree (vmid, payment_id, order_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2945 (class 1259 OID 26509)
|
||||
-- Name: idx_catalog_vmid_code_name; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_catalog_vmid_code_name ON public.catalog USING btree (vmid, code, name);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2935 (class 1259 OID 26132)
|
||||
-- Name: idx_error_vmid_vmtime_code; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_error_vmid_vmtime_code ON public.error USING btree (vmid, vmtime DESC) INCLUDE (code);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2934 (class 1259 OID 26128)
|
||||
-- Name: idx_ingest_received; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_ingest_received ON public.ingest USING btree (received) WHERE (NOT done);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2936 (class 1259 OID 26131)
|
||||
-- Name: idx_inventory_vmid_not_service; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_inventory_vmid_not_service ON public.inventory USING btree (vmid) WITH (fillfactor='10') WHERE (NOT at_service);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2937 (class 1259 OID 26130)
|
||||
-- Name: idx_inventory_vmid_service; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_inventory_vmid_service ON public.inventory USING btree (vmid) WITH (fillfactor='10') WHERE at_service;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2950 (class 1259 OID 55062)
|
||||
-- Name: idx_state_vmid_state_received; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_state_vmid_state_received ON public.state USING btree (vmid, state, received) WITH (fillfactor='10');
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2938 (class 1259 OID 26231)
|
||||
-- Name: idx_tax_job_help; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_tax_job_help ON public.tax_job USING btree (modified) WHERE (state = 'help'::public.tax_job_state);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2939 (class 1259 OID 26230)
|
||||
-- Name: idx_tax_job_sched; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_tax_job_sched ON public.tax_job USING btree (scheduled, modified) WHERE (state = 'sched'::public.tax_job_state);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2942 (class 1259 OID 26244)
|
||||
-- Name: idx_trans_vmid_vmtime; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX idx_trans_vmid_vmtime ON public.trans USING btree (vmid, vmtime);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2943 (class 1259 OID 26243)
|
||||
-- Name: idx_trans_vmtime; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX idx_trans_vmtime ON public.trans USING btree (vmtime);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2955 (class 1259 OID 65021)
|
||||
-- Name: tgchat_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX tgchat_idx ON public.tg_chat USING btree (messageid, fromid, toid, date);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2956 (class 1259 OID 65022)
|
||||
-- Name: tgchat_idx1; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX tgchat_idx1 ON public.tg_chat USING btree (fromid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2957 (class 1259 OID 65023)
|
||||
-- Name: tgchat_idx2; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX tgchat_idx2 ON public.tg_chat USING btree (toid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2944 (class 1259 OID 64901)
|
||||
-- Name: trans_executer; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX trans_executer ON public.trans USING btree (executer);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2961 (class 2620 OID 26251)
|
||||
-- Name: tax_job tax_job_maint_after; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER tax_job_maint_after AFTER INSERT OR UPDATE ON public.tax_job FOR EACH ROW EXECUTE PROCEDURE public.tax_job_maint_after();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2962 (class 2620 OID 26252)
|
||||
-- Name: tax_job tax_job_maint_before; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER tax_job_maint_before BEFORE INSERT OR UPDATE ON public.tax_job FOR EACH ROW EXECUTE PROCEDURE public.tax_job_maint_before();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2963 (class 2620 OID 26253)
|
||||
-- Name: tax_job tax_job_modified; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER tax_job_modified BEFORE UPDATE ON public.tax_job FOR EACH ROW WHEN (((new.ext_id IS DISTINCT FROM old.ext_id) OR (new.data IS DISTINCT FROM old.data) OR (new.notes IS DISTINCT FROM old.notes))) EXECUTE PROCEDURE public.tax_job_modified();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2964 (class 2620 OID 26254)
|
||||
-- Name: trans trans_tax; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER trans_tax AFTER INSERT ON public.trans FOR EACH ROW EXECUTE PROCEDURE public.trans_tax_trigger();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2960 (class 2606 OID 26238)
|
||||
-- Name: trans trans_tax_job_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.trans
|
||||
ADD CONSTRAINT trans_tax_job_id_fkey FOREIGN KEY (tax_job_id) REFERENCES public.tax_job(id) ON UPDATE RESTRICT ON DELETE SET NULL;
|
||||
|
||||
|
||||
-- Completed on 2022-04-27 18:41:38
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
-- Downloaded from: https://github.com/AliiAhmadi/PostScan/blob/27620d20ed609904a16cef08af33ed8f16b984f9/backup.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.3
|
||||
-- Dumped by pg_dump version 16.3
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: malicious_function(); Type: FUNCTION; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.malicious_function() RETURNS void
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
BEGIN
|
||||
PERFORM pg_sleep(10);
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.malicious_function() OWNER TO testuser;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: test; DROP TABLE users;; Type: TABLE; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
CREATE TABLE public."test; DROP TABLE users;" (
|
||||
id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."test; DROP TABLE users;" OWNER TO testuser;
|
||||
|
||||
--
|
||||
-- Name: test; DROP TABLE users;_id_seq; Type: SEQUENCE; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."test; DROP TABLE users;_id_seq"
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."test; DROP TABLE users;_id_seq" OWNER TO testuser;
|
||||
|
||||
--
|
||||
-- Name: test; DROP TABLE users;_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."test; DROP TABLE users;_id_seq" OWNED BY public."test; DROP TABLE users;".id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: test_table; Type: TABLE; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
CREATE TABLE public.test_table (
|
||||
id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.test_table OWNER TO testuser;
|
||||
|
||||
--
|
||||
-- Name: test_table_id_seq; Type: SEQUENCE; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.test_table_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.test_table_id_seq OWNER TO testuser;
|
||||
|
||||
--
|
||||
-- Name: test_table_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.test_table_id_seq OWNED BY public.test_table.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: test; DROP TABLE users; id; Type: DEFAULT; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."test; DROP TABLE users;" ALTER COLUMN id SET DEFAULT nextval('public."test; DROP TABLE users;_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: test_table id; Type: DEFAULT; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.test_table ALTER COLUMN id SET DEFAULT nextval('public.test_table_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: test; DROP TABLE users;; Type: TABLE DATA; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
COPY public."test; DROP TABLE users;" (id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: test_table; Type: TABLE DATA; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
COPY public.test_table (id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: test; DROP TABLE users;_id_seq; Type: SEQUENCE SET; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."test; DROP TABLE users;_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: test_table_id_seq; Type: SEQUENCE SET; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.test_table_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: test_table test_table_pkey; Type: CONSTRAINT; Schema: public; Owner: testuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.test_table
|
||||
ADD CONSTRAINT test_table_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
GRANT ALL ON SCHEMA public TO testuser;
|
||||
|
||||
|
||||
--
|
||||
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO testuser;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
-- Downloaded from: https://github.com/Ansh-Rathod/Musive-backend-2.0/blob/eb320d80d2fa07283bb4ab9351581f4c8757bcad/schema.sql
|
||||
create table Users(
|
||||
id serial primary key,
|
||||
username varchar(28) not null unique,
|
||||
passhash varchar not null
|
||||
);
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
create table public."Artists"(
|
||||
id integer unique not null,
|
||||
username text not null unique,
|
||||
display_name text not null,
|
||||
avatar jsonb,
|
||||
gender varchar,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
create table public."Tracks"(
|
||||
id integer unique not null,
|
||||
user_id integer not null,
|
||||
tags text[] not null DEFAULT '{}',
|
||||
moods text[] not null DEFAULT '{}',
|
||||
genres text[] not null DEFAULT '{}',
|
||||
movements text[] not null DEFAULT '{}',
|
||||
keywords text not null,
|
||||
duration float not null,
|
||||
track_name text not null,
|
||||
download_url text not null,
|
||||
src text not null,
|
||||
cover_image jsonb,
|
||||
PRIMARY KEY(id)
|
||||
);
|
||||
|
||||
alter table if exists songs
|
||||
add constraint user_id_fk FOREIGN KEY (user_id) REFERENCES artists(id)
|
||||
match full on update CASCADE on delete CASCADE;
|
||||
|
||||
create table public."Liked"(
|
||||
id serial primary key,
|
||||
track_id integer not null,
|
||||
username varchar(28) not null
|
||||
);
|
||||
|
||||
alter table public."Liked" add constraint track_id FOREIGN KEY(track_id)
|
||||
REFERENCES public."Tracks"(id) match full on update CASCADE on delete cascade;
|
||||
|
||||
alter table public."Liked" add constraint user_id FOREIGN KEY(username)
|
||||
REFERENCES public."Users"(username) match full on update CASCADE on delete cascade;
|
||||
|
||||
create table public."Collections"(
|
||||
id uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
|
||||
name text not null,
|
||||
username varchar(28) not null,
|
||||
total_tracks integer DEFAULT 0
|
||||
);
|
||||
|
||||
alter table public."Collections" add constraint user_id FOREIGN KEY(username)
|
||||
REFERENCES public."Users"(username) match full on update CASCADE on delete cascade;
|
||||
|
||||
create table public."CollectionItems"(
|
||||
collection_id uuid not null,
|
||||
track_id integer not null
|
||||
);
|
||||
|
||||
|
||||
alter table public."CollectionItems" add constraint collection_id_fk FOREIGN KEY(collection_id)
|
||||
REFERENCES public."Collections"(id) match full on update CASCADE on delete cascade;
|
||||
|
||||
alter table public."CollectionItems" add constraint track_id_fk FOREIGN KEY(track_id)
|
||||
REFERENCES public."Tracks"(id) match full on update CASCADE on delete cascade;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_collections()
|
||||
RETURNS trigger AS $$
|
||||
DECLARE
|
||||
BEGIN
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
EXECUTE 'update public."Collections" set total_tracks=total_tracks+1 where id = $1;'
|
||||
USING NEW.collection_id;
|
||||
END IF;
|
||||
|
||||
IF TG_OP = 'DELETE' THEN
|
||||
EXECUTE 'update public."Collections" set total_tracks=total_tracks-1 where id = $1;'
|
||||
USING OLD.collection_id;
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
CREATE TRIGGER update_collection
|
||||
AFTER INSERT OR DELETE ON public."CollectionItems"
|
||||
FOR EACH ROW EXECUTE PROCEDURE update_collections();
|
||||
|
||||
-- pg_dump -U postgres -h containers-us-west-63.railway.app -p 7771 railway >> sqlfile.sql
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
||||
-- Downloaded from: https://github.com/Boluwatife-AJB/backend-in-node/blob/302739ec5fb1880b77d9cb51636834bdacff16ed/sample.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 15.8 (Homebrew)
|
||||
-- Dumped by pg_dump version 15.8 (Homebrew)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: companies; Type: TABLE; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
CREATE TABLE public.companies (
|
||||
id uuid NOT NULL,
|
||||
name character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.companies OWNER TO "USER";
|
||||
|
||||
--
|
||||
-- Name: employees; Type: TABLE; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
CREATE TABLE public.employees (
|
||||
id uuid NOT NULL,
|
||||
first_name character varying,
|
||||
last_name character varying,
|
||||
email character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.employees OWNER TO "USER";
|
||||
|
||||
--
|
||||
-- Data for Name: companies; Type: TABLE DATA; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
COPY public.companies (id, name) FROM stdin;
|
||||
f5c41428-5f90-4ca6-b167-9c6f5a41bae0 valhalla
|
||||
7874572b-e4ca-4add-958e-3f611649c9bf ghost road
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: employees; Type: TABLE DATA; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
COPY public.employees (id, first_name, last_name, email) FROM stdin;
|
||||
ce4b3817-2ea9-4f4c-9760-8ad30aa807be max maximus max@valhallah.org
|
||||
ce4b3817-2ea9-4f4c-9760-8ad30aa347be mcDonalds williams williams@ghost-road.org
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: companies companies_pkey; Type: CONSTRAINT; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.companies
|
||||
ADD CONSTRAINT companies_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: employees employees_pkey; Type: CONSTRAINT; Schema: public; Owner: USER
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employees
|
||||
ADD CONSTRAINT employees_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,741 @@
|
||||
-- Downloaded from: https://github.com/Chris-Merced/Classic-Messenger-App-Backend/blob/830ae3a7451ff23d2d41943f7a727008e525e190/schema.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.9 (Ubuntu 16.9-0ubuntu0.24.04.1)
|
||||
-- Dumped by pg_dump version 16.9 (Ubuntu 16.9-0ubuntu0.24.04.1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: _heroku; Type: SCHEMA; Schema: -; Owner: chris
|
||||
--
|
||||
|
||||
CREATE SCHEMA _heroku;
|
||||
|
||||
|
||||
ALTER SCHEMA _heroku OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner:
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION pg_stat_statements IS 'track planning and execution statistics of all SQL statements executed';
|
||||
|
||||
|
||||
--
|
||||
-- Name: create_ext(); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.create_ext() RETURNS event_trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
|
||||
DECLARE
|
||||
|
||||
schemaname TEXT;
|
||||
databaseowner TEXT;
|
||||
|
||||
r RECORD;
|
||||
|
||||
BEGIN
|
||||
|
||||
IF tg_tag = 'CREATE EXTENSION' and current_user != 'rds_superuser' THEN
|
||||
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
|
||||
LOOP
|
||||
CONTINUE WHEN r.command_tag != 'CREATE EXTENSION' OR r.object_type != 'extension';
|
||||
|
||||
schemaname = (
|
||||
SELECT n.nspname
|
||||
FROM pg_catalog.pg_extension AS e
|
||||
INNER JOIN pg_catalog.pg_namespace AS n
|
||||
ON e.extnamespace = n.oid
|
||||
WHERE e.oid = r.objid
|
||||
);
|
||||
|
||||
databaseowner = (
|
||||
SELECT pg_catalog.pg_get_userbyid(d.datdba)
|
||||
FROM pg_catalog.pg_database d
|
||||
WHERE d.datname = current_database()
|
||||
);
|
||||
--RAISE NOTICE 'Record for event trigger %, objid: %,tag: %, current_user: %, schema: %, database_owenr: %', r.object_identity, r.objid, tg_tag, current_user, schemaname, databaseowner;
|
||||
IF r.object_identity = 'address_standardizer_data_us' THEN
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'us_gaz');
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'us_lex');
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'us_rules');
|
||||
ELSIF r.object_identity = 'amcheck' THEN
|
||||
EXECUTE format('GRANT EXECUTE ON FUNCTION %I.bt_index_check TO %I;', schemaname, databaseowner);
|
||||
EXECUTE format('GRANT EXECUTE ON FUNCTION %I.bt_index_parent_check TO %I;', schemaname, databaseowner);
|
||||
ELSIF r.object_identity = 'dict_int' THEN
|
||||
EXECUTE format('ALTER TEXT SEARCH DICTIONARY %I.intdict OWNER TO %I;', schemaname, databaseowner);
|
||||
ELSIF r.object_identity = 'pg_partman' THEN
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'part_config');
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'part_config_sub');
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT, UPDATE, INSERT, DELETE', databaseowner, 'custom_time_partitions');
|
||||
ELSIF r.object_identity = 'pg_stat_statements' THEN
|
||||
EXECUTE format('GRANT EXECUTE ON FUNCTION %I.pg_stat_statements_reset TO %I;', schemaname, databaseowner);
|
||||
ELSIF r.object_identity = 'postgis' THEN
|
||||
PERFORM _heroku.postgis_after_create();
|
||||
ELSIF r.object_identity = 'postgis_raster' THEN
|
||||
PERFORM _heroku.postgis_after_create();
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT', databaseowner, 'raster_columns');
|
||||
PERFORM _heroku.grant_table_if_exists(schemaname, 'SELECT', databaseowner, 'raster_overviews');
|
||||
ELSIF r.object_identity = 'postgis_topology' THEN
|
||||
PERFORM _heroku.postgis_after_create();
|
||||
EXECUTE format('GRANT USAGE ON SCHEMA topology TO %I;', databaseowner);
|
||||
EXECUTE format('GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA topology TO %I;', databaseowner);
|
||||
PERFORM _heroku.grant_table_if_exists('topology', 'SELECT, UPDATE, INSERT, DELETE', databaseowner);
|
||||
EXECUTE format('GRANT USAGE, SELECT, UPDATE ON ALL SEQUENCES IN SCHEMA topology TO %I;', databaseowner);
|
||||
ELSIF r.object_identity = 'postgis_tiger_geocoder' THEN
|
||||
PERFORM _heroku.postgis_after_create();
|
||||
EXECUTE format('GRANT USAGE ON SCHEMA tiger TO %I;', databaseowner);
|
||||
EXECUTE format('GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA tiger TO %I;', databaseowner);
|
||||
PERFORM _heroku.grant_table_if_exists('tiger', 'SELECT, UPDATE, INSERT, DELETE', databaseowner);
|
||||
|
||||
EXECUTE format('GRANT USAGE ON SCHEMA tiger_data TO %I;', databaseowner);
|
||||
EXECUTE format('GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA tiger_data TO %I;', databaseowner);
|
||||
PERFORM _heroku.grant_table_if_exists('tiger_data', 'SELECT, UPDATE, INSERT, DELETE', databaseowner);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.create_ext() OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: drop_ext(); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.drop_ext() RETURNS event_trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
|
||||
DECLARE
|
||||
|
||||
schemaname TEXT;
|
||||
databaseowner TEXT;
|
||||
|
||||
r RECORD;
|
||||
|
||||
BEGIN
|
||||
|
||||
IF tg_tag = 'DROP EXTENSION' and current_user != 'rds_superuser' THEN
|
||||
FOR r IN SELECT * FROM pg_event_trigger_dropped_objects()
|
||||
LOOP
|
||||
CONTINUE WHEN r.object_type != 'extension';
|
||||
|
||||
databaseowner = (
|
||||
SELECT pg_catalog.pg_get_userbyid(d.datdba)
|
||||
FROM pg_catalog.pg_database d
|
||||
WHERE d.datname = current_database()
|
||||
);
|
||||
|
||||
--RAISE NOTICE 'Record for event trigger %, objid: %,tag: %, current_user: %, database_owner: %, schemaname: %', r.object_identity, r.objid, tg_tag, current_user, databaseowner, r.schema_name;
|
||||
|
||||
IF r.object_identity = 'postgis_topology' THEN
|
||||
EXECUTE format('DROP SCHEMA IF EXISTS topology');
|
||||
END IF;
|
||||
END LOOP;
|
||||
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.drop_ext() OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: extension_before_drop(); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.extension_before_drop() RETURNS event_trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
|
||||
DECLARE
|
||||
|
||||
query TEXT;
|
||||
|
||||
BEGIN
|
||||
query = (SELECT current_query());
|
||||
|
||||
-- RAISE NOTICE 'executing extension_before_drop: tg_event: %, tg_tag: %, current_user: %, session_user: %, query: %', tg_event, tg_tag, current_user, session_user, query;
|
||||
IF tg_tag = 'DROP EXTENSION' and not pg_has_role(session_user, 'rds_superuser', 'MEMBER') THEN
|
||||
-- DROP EXTENSION [ IF EXISTS ] name [, ...] [ CASCADE | RESTRICT ]
|
||||
IF (regexp_match(query, 'DROP\s+EXTENSION\s+(IF\s+EXISTS)?.*(plpgsql)', 'i') IS NOT NULL) THEN
|
||||
RAISE EXCEPTION 'The plpgsql extension is required for database management and cannot be dropped.';
|
||||
END IF;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.extension_before_drop() OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: grant_table_if_exists(text, text, text, text); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.grant_table_if_exists(alias_schemaname text, grants text, databaseowner text, alias_tablename text DEFAULT NULL::text) RETURNS void
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
|
||||
BEGIN
|
||||
|
||||
IF alias_tablename IS NULL THEN
|
||||
EXECUTE format('GRANT %s ON ALL TABLES IN SCHEMA %I TO %I;', grants, alias_schemaname, databaseowner);
|
||||
ELSE
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE pg_tables.schemaname = alias_schemaname AND pg_tables.tablename = alias_tablename) THEN
|
||||
EXECUTE format('GRANT %s ON TABLE %I.%I TO %I;', grants, alias_schemaname, alias_tablename, databaseowner);
|
||||
END IF;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.grant_table_if_exists(alias_schemaname text, grants text, databaseowner text, alias_tablename text) OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: postgis_after_create(); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.postgis_after_create() RETURNS void
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
DECLARE
|
||||
schemaname TEXT;
|
||||
databaseowner TEXT;
|
||||
BEGIN
|
||||
schemaname = (
|
||||
SELECT n.nspname
|
||||
FROM pg_catalog.pg_extension AS e
|
||||
INNER JOIN pg_catalog.pg_namespace AS n ON e.extnamespace = n.oid
|
||||
WHERE e.extname = 'postgis'
|
||||
);
|
||||
databaseowner = (
|
||||
SELECT pg_catalog.pg_get_userbyid(d.datdba)
|
||||
FROM pg_catalog.pg_database d
|
||||
WHERE d.datname = current_database()
|
||||
);
|
||||
|
||||
EXECUTE format('GRANT EXECUTE ON FUNCTION %I.st_tileenvelope TO %I;', schemaname, databaseowner);
|
||||
EXECUTE format('GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE %I.spatial_ref_sys TO %I;', schemaname, databaseowner);
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.postgis_after_create() OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: validate_extension(); Type: FUNCTION; Schema: _heroku; Owner: chris
|
||||
--
|
||||
|
||||
CREATE FUNCTION _heroku.validate_extension() RETURNS event_trigger
|
||||
LANGUAGE plpgsql SECURITY DEFINER
|
||||
AS $$
|
||||
|
||||
DECLARE
|
||||
|
||||
schemaname TEXT;
|
||||
r RECORD;
|
||||
|
||||
BEGIN
|
||||
|
||||
IF tg_tag = 'CREATE EXTENSION' and current_user != 'rds_superuser' THEN
|
||||
FOR r IN SELECT * FROM pg_event_trigger_ddl_commands()
|
||||
LOOP
|
||||
CONTINUE WHEN r.command_tag != 'CREATE EXTENSION' OR r.object_type != 'extension';
|
||||
|
||||
schemaname = (
|
||||
SELECT n.nspname
|
||||
FROM pg_catalog.pg_extension AS e
|
||||
INNER JOIN pg_catalog.pg_namespace AS n
|
||||
ON e.extnamespace = n.oid
|
||||
WHERE e.oid = r.objid
|
||||
);
|
||||
|
||||
IF schemaname = '_heroku' THEN
|
||||
RAISE EXCEPTION 'Creating extensions in the _heroku schema is not allowed';
|
||||
END IF;
|
||||
END LOOP;
|
||||
END IF;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION _heroku.validate_extension() OWNER TO chris;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: blocked; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.blocked (
|
||||
user_id integer NOT NULL,
|
||||
blocked_id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.blocked OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: conversation_participants; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.conversation_participants (
|
||||
id integer NOT NULL,
|
||||
conversation_id integer,
|
||||
user_id integer,
|
||||
added_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.conversation_participants OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: conversation_participants_id_seq; Type: SEQUENCE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.conversation_participants_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.conversation_participants_id_seq OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: conversation_participants_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.conversation_participants_id_seq OWNED BY public.conversation_participants.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversations; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.conversations (
|
||||
id integer NOT NULL,
|
||||
name character varying(100),
|
||||
is_group boolean DEFAULT false,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.conversations OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: conversations_id_seq; Type: SEQUENCE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.conversations_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.conversations_id_seq OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: conversations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.conversations_id_seq OWNED BY public.conversations.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: friend_requests; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.friend_requests (
|
||||
user_id integer NOT NULL,
|
||||
request_id integer NOT NULL,
|
||||
status character varying(10),
|
||||
CONSTRAINT friend_requests_status_check CHECK (((status)::text = ANY ((ARRAY['pending'::character varying, 'accepted'::character varying, 'rejected'::character varying])::text[])))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.friend_requests OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: friends; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.friends (
|
||||
user_id integer NOT NULL,
|
||||
friend_id integer NOT NULL,
|
||||
CONSTRAINT friends_check CHECK ((user_id < friend_id))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.friends OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: messages; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.messages (
|
||||
id integer NOT NULL,
|
||||
conversation_id integer,
|
||||
sender_id integer,
|
||||
content text NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
is_read boolean DEFAULT false
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.messages OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: messages_id_seq; Type: SEQUENCE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.messages_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.messages_id_seq OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: messages_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.messages_id_seq OWNED BY public.messages.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.sessions (
|
||||
session_id character varying(255) NOT NULL,
|
||||
user_id integer,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at timestamp without time zone
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.sessions OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: users; Type: TABLE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE TABLE public.users (
|
||||
id integer NOT NULL,
|
||||
username character varying(50) NOT NULL,
|
||||
password character varying(255) NOT NULL,
|
||||
email character varying(100),
|
||||
is_admin boolean DEFAULT false,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
is_public boolean DEFAULT true,
|
||||
profile_picture character varying(500) DEFAULT NULL::character varying,
|
||||
about_me character varying(500)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.users OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.users_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.users_id_seq OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversation_participants id; Type: DEFAULT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversation_participants ALTER COLUMN id SET DEFAULT nextval('public.conversation_participants_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversations id; Type: DEFAULT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversations ALTER COLUMN id SET DEFAULT nextval('public.conversations_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: messages id; Type: DEFAULT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.messages ALTER COLUMN id SET DEFAULT nextval('public.messages_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users id; Type: DEFAULT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: blocked blocked_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.blocked
|
||||
ADD CONSTRAINT blocked_pkey PRIMARY KEY (user_id, blocked_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversation_participants conversation_participants_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversation_participants
|
||||
ADD CONSTRAINT conversation_participants_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversations conversations_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversations
|
||||
ADD CONSTRAINT conversations_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: friend_requests friend_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friend_requests
|
||||
ADD CONSTRAINT friend_requests_pkey PRIMARY KEY (user_id, request_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: friends friends_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friends
|
||||
ADD CONSTRAINT friends_pkey PRIMARY KEY (user_id, friend_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: messages messages_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.messages
|
||||
ADD CONSTRAINT messages_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.sessions
|
||||
ADD CONSTRAINT sessions_pkey PRIMARY KEY (session_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_email_key; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_username_key; Type: CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_username_key UNIQUE (username);
|
||||
|
||||
|
||||
--
|
||||
-- Name: blocked blocked_blocked_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.blocked
|
||||
ADD CONSTRAINT blocked_blocked_id_fkey FOREIGN KEY (blocked_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: blocked blocked_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.blocked
|
||||
ADD CONSTRAINT blocked_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversation_participants conversation_participants_conversation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversation_participants
|
||||
ADD CONSTRAINT conversation_participants_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES public.conversations(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: conversation_participants conversation_participants_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.conversation_participants
|
||||
ADD CONSTRAINT conversation_participants_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: friend_requests friend_requests_request_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friend_requests
|
||||
ADD CONSTRAINT friend_requests_request_id_fkey FOREIGN KEY (request_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: friend_requests friend_requests_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friend_requests
|
||||
ADD CONSTRAINT friend_requests_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: friends friends_friend_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friends
|
||||
ADD CONSTRAINT friends_friend_id_fkey FOREIGN KEY (friend_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: friends friends_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.friends
|
||||
ADD CONSTRAINT friends_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: messages messages_conversation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.messages
|
||||
ADD CONSTRAINT messages_conversation_id_fkey FOREIGN KEY (conversation_id) REFERENCES public.conversations(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: messages messages_sender_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.messages
|
||||
ADD CONSTRAINT messages_sender_id_fkey FOREIGN KEY (sender_id) REFERENCES public.users(id) ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- Name: sessions sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: chris
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.sessions
|
||||
ADD CONSTRAINT sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
REVOKE USAGE ON SCHEMA public FROM PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- Name: extension_before_drop; Type: EVENT TRIGGER; Schema: -; Owner: chris
|
||||
--
|
||||
|
||||
CREATE EVENT TRIGGER extension_before_drop ON ddl_command_start
|
||||
EXECUTE FUNCTION _heroku.extension_before_drop();
|
||||
|
||||
|
||||
ALTER EVENT TRIGGER extension_before_drop OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: log_create_ext; Type: EVENT TRIGGER; Schema: -; Owner: chris
|
||||
--
|
||||
|
||||
CREATE EVENT TRIGGER log_create_ext ON ddl_command_end
|
||||
EXECUTE FUNCTION _heroku.create_ext();
|
||||
|
||||
|
||||
ALTER EVENT TRIGGER log_create_ext OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: log_drop_ext; Type: EVENT TRIGGER; Schema: -; Owner: chris
|
||||
--
|
||||
|
||||
CREATE EVENT TRIGGER log_drop_ext ON sql_drop
|
||||
EXECUTE FUNCTION _heroku.drop_ext();
|
||||
|
||||
|
||||
ALTER EVENT TRIGGER log_drop_ext OWNER TO chris;
|
||||
|
||||
--
|
||||
-- Name: validate_extension; Type: EVENT TRIGGER; Schema: -; Owner: chris
|
||||
--
|
||||
|
||||
CREATE EVENT TRIGGER validate_extension ON ddl_command_end
|
||||
EXECUTE FUNCTION _heroku.validate_extension();
|
||||
|
||||
|
||||
ALTER EVENT TRIGGER validate_extension OWNER TO chris;
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,715 @@
|
||||
-- Downloaded from: https://github.com/Clar17y/Football-Events/blob/9783f281e6e568f8c3fa7cbdfa8995229870e1a7/schema.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.8 (Debian 16.8-1.pgdg120+1)
|
||||
-- Dumped by pg_dump version 17.4
|
||||
|
||||
-- Started on 2025-07-16 10:07:12
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 6 (class 2615 OID 24591)
|
||||
-- Name: grassroots; Type: SCHEMA; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SCHEMA grassroots;
|
||||
|
||||
|
||||
ALTER SCHEMA grassroots OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 853 (class 1247 OID 24604)
|
||||
-- Name: event_kind; Type: TYPE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TYPE grassroots.event_kind AS ENUM (
|
||||
'goal',
|
||||
'assist',
|
||||
'key_pass',
|
||||
'save',
|
||||
'interception',
|
||||
'tackle',
|
||||
'foul',
|
||||
'penalty',
|
||||
'free_kick',
|
||||
'ball_out',
|
||||
'own_goal'
|
||||
);
|
||||
|
||||
|
||||
ALTER TYPE grassroots.event_kind OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 886 (class 1247 OID 25269)
|
||||
-- Name: position_code; Type: TYPE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TYPE grassroots.position_code AS ENUM (
|
||||
'GK',
|
||||
'CB',
|
||||
'RCB',
|
||||
'LCB',
|
||||
'SW',
|
||||
'RB',
|
||||
'LB',
|
||||
'RWB',
|
||||
'LWB',
|
||||
'CDM',
|
||||
'RDM',
|
||||
'LDM',
|
||||
'CM',
|
||||
'RCM',
|
||||
'LCM',
|
||||
'CAM',
|
||||
'RAM',
|
||||
'LAM',
|
||||
'RM',
|
||||
'LM',
|
||||
'RW',
|
||||
'LW',
|
||||
'RF',
|
||||
'LF',
|
||||
'CF',
|
||||
'ST',
|
||||
'SS',
|
||||
'AM',
|
||||
'DM',
|
||||
'WM',
|
||||
'WB',
|
||||
'FB',
|
||||
'SUB',
|
||||
'BENCH'
|
||||
);
|
||||
|
||||
|
||||
ALTER TYPE grassroots.position_code OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 880 (class 1247 OID 25247)
|
||||
-- Name: user_role; Type: TYPE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TYPE grassroots.user_role AS ENUM (
|
||||
'ADMIN',
|
||||
'USER'
|
||||
);
|
||||
|
||||
|
||||
ALTER TYPE grassroots.user_role OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1255 OID 25266)
|
||||
-- Name: update_updated_at_column(); Type: FUNCTION; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION grassroots.update_updated_at_column() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION grassroots.update_updated_at_column() OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 24668)
|
||||
-- Name: awards; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.awards (
|
||||
award_id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
season_id uuid NOT NULL,
|
||||
player_id uuid NOT NULL,
|
||||
category text NOT NULL,
|
||||
notes text,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.awards OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 24658)
|
||||
-- Name: events; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.events (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
match_id uuid NOT NULL,
|
||||
season_id uuid NOT NULL,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
period_number integer,
|
||||
clock_ms integer,
|
||||
kind grassroots.event_kind NOT NULL,
|
||||
team_id uuid,
|
||||
player_id uuid,
|
||||
notes text,
|
||||
sentiment integer DEFAULT 0 NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.events OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 24691)
|
||||
-- Name: lineup; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.lineup (
|
||||
match_id uuid NOT NULL,
|
||||
player_id uuid NOT NULL,
|
||||
start_min double precision DEFAULT 0 NOT NULL,
|
||||
end_min double precision,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL,
|
||||
"position" grassroots.position_code NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.lineup OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 24700)
|
||||
-- Name: match_awards; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.match_awards (
|
||||
match_award_id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
match_id uuid NOT NULL,
|
||||
player_id uuid NOT NULL,
|
||||
category text NOT NULL,
|
||||
notes text,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.match_awards OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 24645)
|
||||
-- Name: matches; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.matches (
|
||||
match_id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
season_id uuid NOT NULL,
|
||||
kickoff_ts timestamp(6) with time zone NOT NULL,
|
||||
competition text,
|
||||
home_team_id uuid NOT NULL,
|
||||
away_team_id uuid NOT NULL,
|
||||
venue text,
|
||||
duration_mins integer DEFAULT 50 NOT NULL,
|
||||
period_format text DEFAULT 'quarter'::text NOT NULL,
|
||||
our_score integer DEFAULT 0 NOT NULL,
|
||||
opponent_score integer DEFAULT 0 NOT NULL,
|
||||
notes text,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.matches OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 24636)
|
||||
-- Name: players; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.players (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
full_name text NOT NULL,
|
||||
squad_number integer,
|
||||
dob date,
|
||||
notes text,
|
||||
current_team uuid,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL,
|
||||
preferred_pos grassroots.position_code
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.players OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1259 OID 24727)
|
||||
-- Name: seasons; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.seasons (
|
||||
season_id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
label text NOT NULL,
|
||||
start_date date NOT NULL,
|
||||
end_date date NOT NULL,
|
||||
is_current boolean DEFAULT false NOT NULL,
|
||||
description text,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.seasons OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 24627)
|
||||
-- Name: teams; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.teams (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
name text NOT NULL,
|
||||
home_kit_primary character varying(7),
|
||||
home_kit_secondary character varying(7),
|
||||
away_kit_primary character varying(7),
|
||||
away_kit_secondary character varying(7),
|
||||
logo_url text,
|
||||
created_at timestamp(6) with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(6) with time zone,
|
||||
created_by_user_id uuid NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid,
|
||||
is_deleted boolean DEFAULT false NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.teams OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1259 OID 25251)
|
||||
-- Name: users; Type: TABLE; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE grassroots.users (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
email text NOT NULL,
|
||||
password_hash text NOT NULL,
|
||||
first_name text,
|
||||
last_name text,
|
||||
role grassroots.user_role DEFAULT 'USER'::grassroots.user_role NOT NULL,
|
||||
email_verified boolean DEFAULT false NOT NULL,
|
||||
created_at timestamp(3) without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
updated_at timestamp(3) without time zone NOT NULL,
|
||||
is_deleted boolean DEFAULT false NOT NULL,
|
||||
deleted_at timestamp(3) without time zone,
|
||||
deleted_by_user_id uuid
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE grassroots.users OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 3293 (class 2606 OID 24676)
|
||||
-- Name: awards awards_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.awards
|
||||
ADD CONSTRAINT awards_pkey PRIMARY KEY (award_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3291 (class 2606 OID 24667)
|
||||
-- Name: events events_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.events
|
||||
ADD CONSTRAINT events_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3295 (class 2606 OID 24699)
|
||||
-- Name: lineup lineup_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.lineup
|
||||
ADD CONSTRAINT lineup_pkey PRIMARY KEY (match_id, player_id, start_min);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3298 (class 2606 OID 24708)
|
||||
-- Name: match_awards match_awards_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.match_awards
|
||||
ADD CONSTRAINT match_awards_pkey PRIMARY KEY (match_award_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3289 (class 2606 OID 24657)
|
||||
-- Name: matches matches_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_pkey PRIMARY KEY (match_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3287 (class 2606 OID 24644)
|
||||
-- Name: players players_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.players
|
||||
ADD CONSTRAINT players_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3301 (class 2606 OID 24736)
|
||||
-- Name: seasons seasons_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.seasons
|
||||
ADD CONSTRAINT seasons_pkey PRIMARY KEY (season_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3284 (class 2606 OID 24635)
|
||||
-- Name: teams teams_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.teams
|
||||
ADD CONSTRAINT teams_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3303 (class 2606 OID 25345)
|
||||
-- Name: users users_email_key; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.users
|
||||
ADD CONSTRAINT users_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3305 (class 2606 OID 25263)
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3296 (class 1259 OID 24739)
|
||||
-- Name: match_awards_match_id_category_key; Type: INDEX; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX match_awards_match_id_category_key ON grassroots.match_awards USING btree (match_id, category);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3285 (class 1259 OID 24738)
|
||||
-- Name: players_fullname_team_unique; Type: INDEX; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX players_fullname_team_unique ON grassroots.players USING btree (full_name, current_team);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3299 (class 1259 OID 24740)
|
||||
-- Name: seasons_label_key; Type: INDEX; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX seasons_label_key ON grassroots.seasons USING btree (label);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3282 (class 1259 OID 24737)
|
||||
-- Name: teams_name_key; Type: INDEX; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX teams_name_key ON grassroots.teams USING btree (name);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3332 (class 2620 OID 25267)
|
||||
-- Name: users update_users_updated_at; Type: TRIGGER; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER update_users_updated_at BEFORE UPDATE ON grassroots.users FOR EACH ROW EXECUTE FUNCTION grassroots.update_updated_at_column();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3320 (class 2606 OID 25410)
|
||||
-- Name: awards awards_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.awards
|
||||
ADD CONSTRAINT awards_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3321 (class 2606 OID 25415)
|
||||
-- Name: awards awards_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.awards
|
||||
ADD CONSTRAINT awards_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3322 (class 2606 OID 24776)
|
||||
-- Name: awards awards_player_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.awards
|
||||
ADD CONSTRAINT awards_player_id_fkey FOREIGN KEY (player_id) REFERENCES grassroots.players(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3323 (class 2606 OID 24781)
|
||||
-- Name: awards awards_season_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.awards
|
||||
ADD CONSTRAINT awards_season_id_fkey FOREIGN KEY (season_id) REFERENCES grassroots.seasons(season_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3316 (class 2606 OID 25400)
|
||||
-- Name: events events_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.events
|
||||
ADD CONSTRAINT events_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3317 (class 2606 OID 25405)
|
||||
-- Name: events events_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.events
|
||||
ADD CONSTRAINT events_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3318 (class 2606 OID 24766)
|
||||
-- Name: events events_match_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.events
|
||||
ADD CONSTRAINT events_match_id_fkey FOREIGN KEY (match_id) REFERENCES grassroots.matches(match_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3319 (class 2606 OID 24771)
|
||||
-- Name: events events_team_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.events
|
||||
ADD CONSTRAINT events_team_id_fkey FOREIGN KEY (team_id) REFERENCES grassroots.teams(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3324 (class 2606 OID 25420)
|
||||
-- Name: lineup lineup_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.lineup
|
||||
ADD CONSTRAINT lineup_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3325 (class 2606 OID 25425)
|
||||
-- Name: lineup lineup_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.lineup
|
||||
ADD CONSTRAINT lineup_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3326 (class 2606 OID 24786)
|
||||
-- Name: lineup lineup_match_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.lineup
|
||||
ADD CONSTRAINT lineup_match_id_fkey FOREIGN KEY (match_id) REFERENCES grassroots.matches(match_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3327 (class 2606 OID 24791)
|
||||
-- Name: lineup lineup_player_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.lineup
|
||||
ADD CONSTRAINT lineup_player_id_fkey FOREIGN KEY (player_id) REFERENCES grassroots.players(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3328 (class 2606 OID 24801)
|
||||
-- Name: match_awards match_awards_match_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.match_awards
|
||||
ADD CONSTRAINT match_awards_match_id_fkey FOREIGN KEY (match_id) REFERENCES grassroots.matches(match_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3329 (class 2606 OID 24806)
|
||||
-- Name: match_awards match_awards_player_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.match_awards
|
||||
ADD CONSTRAINT match_awards_player_id_fkey FOREIGN KEY (player_id) REFERENCES grassroots.players(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3311 (class 2606 OID 24751)
|
||||
-- Name: matches matches_away_team_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_away_team_id_fkey FOREIGN KEY (away_team_id) REFERENCES grassroots.teams(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3312 (class 2606 OID 25390)
|
||||
-- Name: matches matches_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3313 (class 2606 OID 25395)
|
||||
-- Name: matches matches_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3314 (class 2606 OID 24756)
|
||||
-- Name: matches matches_home_team_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_home_team_id_fkey FOREIGN KEY (home_team_id) REFERENCES grassroots.teams(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3315 (class 2606 OID 24761)
|
||||
-- Name: matches matches_season_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.matches
|
||||
ADD CONSTRAINT matches_season_id_fkey FOREIGN KEY (season_id) REFERENCES grassroots.seasons(season_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3308 (class 2606 OID 25380)
|
||||
-- Name: players players_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.players
|
||||
ADD CONSTRAINT players_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3309 (class 2606 OID 24741)
|
||||
-- Name: players players_current_team_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.players
|
||||
ADD CONSTRAINT players_current_team_fkey FOREIGN KEY (current_team) REFERENCES grassroots.teams(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3310 (class 2606 OID 25385)
|
||||
-- Name: players players_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.players
|
||||
ADD CONSTRAINT players_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3330 (class 2606 OID 25435)
|
||||
-- Name: seasons seasons_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.seasons
|
||||
ADD CONSTRAINT seasons_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3331 (class 2606 OID 25440)
|
||||
-- Name: seasons seasons_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.seasons
|
||||
ADD CONSTRAINT seasons_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3306 (class 2606 OID 25370)
|
||||
-- Name: teams teams_created_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.teams
|
||||
ADD CONSTRAINT teams_created_by_user_id_fkey FOREIGN KEY (created_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3307 (class 2606 OID 25375)
|
||||
-- Name: teams teams_deleted_by_user_id_fkey; Type: FK CONSTRAINT; Schema: grassroots; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY grassroots.teams
|
||||
ADD CONSTRAINT teams_deleted_by_user_id_fkey FOREIGN KEY (deleted_by_user_id) REFERENCES grassroots.users(id) ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
|
||||
|
||||
-- Completed on 2025-07-16 10:07:12
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,949 @@
|
||||
-- Downloaded from: https://github.com/DRON12261/EduVault/blob/d95f919c69452719e016c3afc53eb24280c11453/backup.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 17.4
|
||||
-- Dumped by pg_dump version 17.4
|
||||
|
||||
-- Started on 2025-05-04 21:20:55
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 4 (class 2615 OID 2200)
|
||||
-- Name: public; Type: SCHEMA; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
CREATE SCHEMA IF NOT EXISTS public;
|
||||
|
||||
|
||||
ALTER SCHEMA public OWNER TO pg_database_owner;
|
||||
|
||||
--
|
||||
-- TOC entry 4900 (class 0 OID 0)
|
||||
-- Dependencies: 4
|
||||
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
COMMENT ON SCHEMA public IS 'standard public schema';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 237 (class 1255 OID 16628)
|
||||
-- Name: Login(character varying, character varying); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public."Login"(login_to_check character varying, password_to_check character varying) RETURNS boolean
|
||||
LANGUAGE plpgsql
|
||||
AS $$DECLARE
|
||||
permission boolean;
|
||||
BEGIN
|
||||
SELECT
|
||||
EXISTS
|
||||
(
|
||||
SELECT * FROM "Users"
|
||||
WHERE "Users".login = login_to_check
|
||||
AND "Users".password = password_to_check
|
||||
)
|
||||
INTO permission;
|
||||
|
||||
RETURN permission;
|
||||
END;$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public."Login"(login_to_check character varying, password_to_check character varying) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 238 (class 1255 OID 16636)
|
||||
-- Name: test_func(character varying, character varying); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.test_func(character varying, character varying) RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $$DECLARE
|
||||
kek integer;
|
||||
BEGIN
|
||||
SELECT user_id from "Users" into kek;
|
||||
RETURN kek;
|
||||
END;$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.test_func(character varying, character varying) OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1259 OID 16459)
|
||||
-- Name: AccessRights; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."AccessRights" (
|
||||
accessright_id bigint NOT NULL,
|
||||
user_id bigint,
|
||||
role_id bigint,
|
||||
accessrighttype_id bigint NOT NULL,
|
||||
record_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."AccessRights" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 230 (class 1259 OID 16509)
|
||||
-- Name: AccessRightsTypes; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."AccessRightsTypes" (
|
||||
accessrighttype_id bigint NOT NULL,
|
||||
artname character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."AccessRightsTypes" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 229 (class 1259 OID 16508)
|
||||
-- Name: AccessRightsTypes_art_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."AccessRightsTypes_art_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."AccessRightsTypes_art_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4901 (class 0 OID 0)
|
||||
-- Dependencies: 229
|
||||
-- Name: AccessRightsTypes_art_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."AccessRightsTypes_art_id_seq" OWNED BY public."AccessRightsTypes".accessrighttype_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 16458)
|
||||
-- Name: AccessRights_accessright_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."AccessRights_accessright_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."AccessRights_accessright_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4902 (class 0 OID 0)
|
||||
-- Dependencies: 223
|
||||
-- Name: AccessRights_accessright_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."AccessRights_accessright_id_seq" OWNED BY public."AccessRights".accessright_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 228 (class 1259 OID 16475)
|
||||
-- Name: Fields; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."Fields" (
|
||||
field_id bigint NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
record_id bigint NOT NULL,
|
||||
value character varying,
|
||||
filetypefield_id bigint
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."Fields" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1259 OID 16466)
|
||||
-- Name: FileTypes; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."FileTypes" (
|
||||
filetype_id bigint NOT NULL,
|
||||
typename character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."FileTypes" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 234 (class 1259 OID 16540)
|
||||
-- Name: FileTypesFields; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."FileTypesFields" (
|
||||
filetypefield_id bigint NOT NULL,
|
||||
filetype_id bigint NOT NULL,
|
||||
name character varying NOT NULL,
|
||||
isrequired boolean NOT NULL,
|
||||
prefilling boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."FileTypesFields" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 233 (class 1259 OID 16539)
|
||||
-- Name: FileTypesFields_filetypefield_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."FileTypesFields_filetypefield_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."FileTypesFields_filetypefield_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4903 (class 0 OID 0)
|
||||
-- Dependencies: 233
|
||||
-- Name: FileTypesFields_filetypefield_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."FileTypesFields_filetypefield_id_seq" OWNED BY public."FileTypesFields".filetypefield_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1259 OID 16465)
|
||||
-- Name: FileTypes_filetype_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."FileTypes_filetype_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."FileTypes_filetype_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4904 (class 0 OID 0)
|
||||
-- Dependencies: 225
|
||||
-- Name: FileTypes_filetype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."FileTypes_filetype_id_seq" OWNED BY public."FileTypes".filetype_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 16431)
|
||||
-- Name: Records; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."Records" (
|
||||
record_id bigint NOT NULL,
|
||||
filetype_id bigint NOT NULL,
|
||||
name character varying,
|
||||
filepath character varying,
|
||||
author character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."Records" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 16430)
|
||||
-- Name: Metadata_metadata_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."Metadata_metadata_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."Metadata_metadata_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4905 (class 0 OID 0)
|
||||
-- Dependencies: 217
|
||||
-- Name: Metadata_metadata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."Metadata_metadata_id_seq" OWNED BY public."Records".record_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 232 (class 1259 OID 16523)
|
||||
-- Name: RecordsRelations; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."RecordsRelations" (
|
||||
relation_id bigint NOT NULL,
|
||||
sourcerecord bigint NOT NULL,
|
||||
targetrecord bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."RecordsRelations" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 231 (class 1259 OID 16522)
|
||||
-- Name: RecordsRelations_relation_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."RecordsRelations_relation_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."RecordsRelations_relation_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4906 (class 0 OID 0)
|
||||
-- Dependencies: 231
|
||||
-- Name: RecordsRelations_relation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."RecordsRelations_relation_id_seq" OWNED BY public."RecordsRelations".relation_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 16449)
|
||||
-- Name: Roles; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."Roles" (
|
||||
role_id bigint NOT NULL,
|
||||
rolename character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."Roles" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 16448)
|
||||
-- Name: Roles_role_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."Roles_role_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."Roles_role_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4907 (class 0 OID 0)
|
||||
-- Dependencies: 221
|
||||
-- Name: Roles_role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."Roles_role_id_seq" OWNED BY public."Roles".role_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 227 (class 1259 OID 16474)
|
||||
-- Name: UserMetadata_usermetadata_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."UserMetadata_usermetadata_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."UserMetadata_usermetadata_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4908 (class 0 OID 0)
|
||||
-- Dependencies: 227
|
||||
-- Name: UserMetadata_usermetadata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."UserMetadata_usermetadata_id_seq" OWNED BY public."Fields".field_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 16440)
|
||||
-- Name: Users; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."Users" (
|
||||
user_id bigint NOT NULL,
|
||||
login character varying NOT NULL,
|
||||
password character varying NOT NULL,
|
||||
name character varying,
|
||||
usertype bigint
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."Users" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 235 (class 1259 OID 16571)
|
||||
-- Name: UsersRoles; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public."UsersRoles" (
|
||||
usersroles_id bigint NOT NULL,
|
||||
user_id bigint NOT NULL,
|
||||
role_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public."UsersRoles" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 236 (class 1259 OID 16574)
|
||||
-- Name: UsersRoles_usersroles_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."UsersRoles_usersroles_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."UsersRoles_usersroles_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4909 (class 0 OID 0)
|
||||
-- Dependencies: 236
|
||||
-- Name: UsersRoles_usersroles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."UsersRoles_usersroles_id_seq" OWNED BY public."UsersRoles".usersroles_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 16439)
|
||||
-- Name: Users_user_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public."Users_user_id_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public."Users_user_id_seq" OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4910 (class 0 OID 0)
|
||||
-- Dependencies: 219
|
||||
-- Name: Users_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public."Users_user_id_seq" OWNED BY public."Users".user_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4691 (class 2604 OID 16562)
|
||||
-- Name: AccessRights accessright_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights" ALTER COLUMN accessright_id SET DEFAULT nextval('public."AccessRights_accessright_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4694 (class 2604 OID 16563)
|
||||
-- Name: AccessRightsTypes accessrighttype_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRightsTypes" ALTER COLUMN accessrighttype_id SET DEFAULT nextval('public."AccessRightsTypes_art_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4693 (class 2604 OID 16569)
|
||||
-- Name: Fields field_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Fields" ALTER COLUMN field_id SET DEFAULT nextval('public."UserMetadata_usermetadata_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4692 (class 2604 OID 16564)
|
||||
-- Name: FileTypes filetype_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."FileTypes" ALTER COLUMN filetype_id SET DEFAULT nextval('public."FileTypes_filetype_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4696 (class 2604 OID 16565)
|
||||
-- Name: FileTypesFields filetypefield_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."FileTypesFields" ALTER COLUMN filetypefield_id SET DEFAULT nextval('public."FileTypesFields_filetypefield_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4688 (class 2604 OID 16566)
|
||||
-- Name: Records record_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Records" ALTER COLUMN record_id SET DEFAULT nextval('public."Metadata_metadata_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4695 (class 2604 OID 16567)
|
||||
-- Name: RecordsRelations relation_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."RecordsRelations" ALTER COLUMN relation_id SET DEFAULT nextval('public."RecordsRelations_relation_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4690 (class 2604 OID 16568)
|
||||
-- Name: Roles role_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Roles" ALTER COLUMN role_id SET DEFAULT nextval('public."Roles_role_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4689 (class 2604 OID 16570)
|
||||
-- Name: Users user_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Users" ALTER COLUMN user_id SET DEFAULT nextval('public."Users_user_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4697 (class 2604 OID 16575)
|
||||
-- Name: UsersRoles usersroles_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UsersRoles" ALTER COLUMN usersroles_id SET DEFAULT nextval('public."UsersRoles_usersroles_id_seq"'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4882 (class 0 OID 16459)
|
||||
-- Dependencies: 224
|
||||
-- Data for Name: AccessRights; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."AccessRights" (accessright_id, user_id, role_id, accessrighttype_id, record_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4888 (class 0 OID 16509)
|
||||
-- Dependencies: 230
|
||||
-- Data for Name: AccessRightsTypes; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."AccessRightsTypes" (accessrighttype_id, artname) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4886 (class 0 OID 16475)
|
||||
-- Dependencies: 228
|
||||
-- Data for Name: Fields; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."Fields" (field_id, name, record_id, value, filetypefield_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4884 (class 0 OID 16466)
|
||||
-- Dependencies: 226
|
||||
-- Data for Name: FileTypes; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."FileTypes" (filetype_id, typename) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4892 (class 0 OID 16540)
|
||||
-- Dependencies: 234
|
||||
-- Data for Name: FileTypesFields; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."FileTypesFields" (filetypefield_id, filetype_id, name, isrequired, prefilling) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4876 (class 0 OID 16431)
|
||||
-- Dependencies: 218
|
||||
-- Data for Name: Records; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."Records" (record_id, filetype_id, name, filepath, author) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4890 (class 0 OID 16523)
|
||||
-- Dependencies: 232
|
||||
-- Data for Name: RecordsRelations; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."RecordsRelations" (relation_id, sourcerecord, targetrecord) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4880 (class 0 OID 16449)
|
||||
-- Dependencies: 222
|
||||
-- Data for Name: Roles; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."Roles" (role_id, rolename) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4878 (class 0 OID 16440)
|
||||
-- Dependencies: 220
|
||||
-- Data for Name: Users; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."Users" (user_id, login, password, name, usertype) FROM stdin;
|
||||
1 test test TestUser 1
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4893 (class 0 OID 16571)
|
||||
-- Dependencies: 235
|
||||
-- Data for Name: UsersRoles; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public."UsersRoles" (usersroles_id, user_id, role_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4911 (class 0 OID 0)
|
||||
-- Dependencies: 229
|
||||
-- Name: AccessRightsTypes_art_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."AccessRightsTypes_art_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4912 (class 0 OID 0)
|
||||
-- Dependencies: 223
|
||||
-- Name: AccessRights_accessright_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."AccessRights_accessright_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4913 (class 0 OID 0)
|
||||
-- Dependencies: 233
|
||||
-- Name: FileTypesFields_filetypefield_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."FileTypesFields_filetypefield_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4914 (class 0 OID 0)
|
||||
-- Dependencies: 225
|
||||
-- Name: FileTypes_filetype_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."FileTypes_filetype_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4915 (class 0 OID 0)
|
||||
-- Dependencies: 217
|
||||
-- Name: Metadata_metadata_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."Metadata_metadata_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4916 (class 0 OID 0)
|
||||
-- Dependencies: 231
|
||||
-- Name: RecordsRelations_relation_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."RecordsRelations_relation_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4917 (class 0 OID 0)
|
||||
-- Dependencies: 221
|
||||
-- Name: Roles_role_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."Roles_role_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4918 (class 0 OID 0)
|
||||
-- Dependencies: 227
|
||||
-- Name: UserMetadata_usermetadata_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."UserMetadata_usermetadata_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4919 (class 0 OID 0)
|
||||
-- Dependencies: 236
|
||||
-- Name: UsersRoles_usersroles_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."UsersRoles_usersroles_id_seq"', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4920 (class 0 OID 0)
|
||||
-- Dependencies: 219
|
||||
-- Name: Users_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."Users_user_id_seq"', 1, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4711 (class 2606 OID 16516)
|
||||
-- Name: AccessRightsTypes AccessRightsTypes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRightsTypes"
|
||||
ADD CONSTRAINT "AccessRightsTypes_pkey" PRIMARY KEY (accessrighttype_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4705 (class 2606 OID 16464)
|
||||
-- Name: AccessRights AccessRights_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights"
|
||||
ADD CONSTRAINT "AccessRights_pkey" PRIMARY KEY (accessright_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4715 (class 2606 OID 16547)
|
||||
-- Name: FileTypesFields FileTypesFields_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."FileTypesFields"
|
||||
ADD CONSTRAINT "FileTypesFields_pkey" PRIMARY KEY (filetypefield_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4707 (class 2606 OID 16473)
|
||||
-- Name: FileTypes FileTypes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."FileTypes"
|
||||
ADD CONSTRAINT "FileTypes_pkey" PRIMARY KEY (filetype_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4699 (class 2606 OID 16438)
|
||||
-- Name: Records Metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Records"
|
||||
ADD CONSTRAINT "Metadata_pkey" PRIMARY KEY (record_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4713 (class 2606 OID 16528)
|
||||
-- Name: RecordsRelations RecordsRelations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."RecordsRelations"
|
||||
ADD CONSTRAINT "RecordsRelations_pkey" PRIMARY KEY (relation_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4703 (class 2606 OID 16456)
|
||||
-- Name: Roles Roles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Roles"
|
||||
ADD CONSTRAINT "Roles_pkey" PRIMARY KEY (role_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4709 (class 2606 OID 16482)
|
||||
-- Name: Fields UserMetadata_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Fields"
|
||||
ADD CONSTRAINT "UserMetadata_pkey" PRIMARY KEY (field_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4717 (class 2606 OID 16580)
|
||||
-- Name: UsersRoles UsersRoles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UsersRoles"
|
||||
ADD CONSTRAINT "UsersRoles_pkey" PRIMARY KEY (usersroles_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4701 (class 2606 OID 16447)
|
||||
-- Name: Users Users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Users"
|
||||
ADD CONSTRAINT "Users_pkey" PRIMARY KEY (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4719 (class 2606 OID 16517)
|
||||
-- Name: AccessRights accessrights_ART; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights"
|
||||
ADD CONSTRAINT "accessrights_ART" FOREIGN KEY (accessrighttype_id) REFERENCES public."AccessRightsTypes"(accessrighttype_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4720 (class 2606 OID 16498)
|
||||
-- Name: AccessRights accessrights_records; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights"
|
||||
ADD CONSTRAINT accessrights_records FOREIGN KEY (record_id) REFERENCES public."Records"(record_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4721 (class 2606 OID 16493)
|
||||
-- Name: AccessRights accessrights_roles; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights"
|
||||
ADD CONSTRAINT accessrights_roles FOREIGN KEY (role_id) REFERENCES public."Roles"(role_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4722 (class 2606 OID 16488)
|
||||
-- Name: AccessRights accessrights_users; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."AccessRights"
|
||||
ADD CONSTRAINT accessrights_users FOREIGN KEY (user_id) REFERENCES public."Users"(user_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4723 (class 2606 OID 16591)
|
||||
-- Name: Fields files_filetypesfields; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Fields"
|
||||
ADD CONSTRAINT files_filetypesfields FOREIGN KEY (filetypefield_id) REFERENCES public."FileTypesFields"(filetypefield_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4724 (class 2606 OID 16503)
|
||||
-- Name: Fields files_records; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Fields"
|
||||
ADD CONSTRAINT files_records FOREIGN KEY (record_id) REFERENCES public."Records"(record_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4727 (class 2606 OID 16548)
|
||||
-- Name: FileTypesFields filetypesfields_filetypes; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."FileTypesFields"
|
||||
ADD CONSTRAINT filetypesfields_filetypes FOREIGN KEY (filetype_id) REFERENCES public."FileTypes"(filetype_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4718 (class 2606 OID 16483)
|
||||
-- Name: Records metadata_filetypes; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."Records"
|
||||
ADD CONSTRAINT metadata_filetypes FOREIGN KEY (filetype_id) REFERENCES public."FileTypes"(filetype_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4725 (class 2606 OID 16529)
|
||||
-- Name: RecordsRelations sourcerecord_records; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."RecordsRelations"
|
||||
ADD CONSTRAINT sourcerecord_records FOREIGN KEY (sourcerecord) REFERENCES public."Records"(record_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4726 (class 2606 OID 16534)
|
||||
-- Name: RecordsRelations targetrecord_records; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."RecordsRelations"
|
||||
ADD CONSTRAINT targetrecord_records FOREIGN KEY (targetrecord) REFERENCES public."Records"(record_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4728 (class 2606 OID 16586)
|
||||
-- Name: UsersRoles usersroles_roles; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UsersRoles"
|
||||
ADD CONSTRAINT usersroles_roles FOREIGN KEY (role_id) REFERENCES public."Roles"(role_id) NOT VALID;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4729 (class 2606 OID 16581)
|
||||
-- Name: UsersRoles usersroles_users; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public."UsersRoles"
|
||||
ADD CONSTRAINT usersroles_users FOREIGN KEY (user_id) REFERENCES public."Users"(user_id) NOT VALID;
|
||||
|
||||
|
||||
-- Completed on 2025-05-04 21:20:56
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,606 @@
|
||||
-- Downloaded from: https://github.com/DmitryAntipin151002/Diplom/blob/350c6c1b05e8ce85abe2eca8a77acacf5b14e4d4/dump_AuthS.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 17.4
|
||||
-- Dumped by pg_dump version 17.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: update_activity_stats(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.update_activity_stats() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
UPDATE user_profiles
|
||||
SET
|
||||
total_activities = (SELECT COUNT(*) FROM user_activities WHERE user_id = NEW.user_id),
|
||||
total_distance = (SELECT COALESCE(SUM(distance), 0) FROM user_activities WHERE user_id = NEW.user_id),
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE user_id = NEW.user_id;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.update_activity_stats() OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: event; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.event (
|
||||
id integer NOT NULL,
|
||||
name character varying(255),
|
||||
description text,
|
||||
event_date timestamp without time zone,
|
||||
max_participants integer,
|
||||
organizer_id uuid
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.event OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: event_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.event_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.event_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: event_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.event_id_seq OWNED BY public.event.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_participant; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.event_participant (
|
||||
id integer NOT NULL,
|
||||
user_id uuid,
|
||||
joined_at timestamp without time zone,
|
||||
event_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.event_participant OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: event_participant_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.event_participant_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.event_participant_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: event_participant_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.event_participant_id_seq OWNED BY public.event_participant.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: role; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.role (
|
||||
id integer NOT NULL,
|
||||
name character varying(50) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.role OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: role_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.role_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.role_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: role_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.role_id_seq OWNED BY public.role.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: status; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.status (
|
||||
id integer NOT NULL,
|
||||
name character varying(50) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.status OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: status_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.status_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.status_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: status_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.status_id_seq OWNED BY public.status.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_activities; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_activities (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
user_id uuid,
|
||||
activity_type character varying(50) NOT NULL,
|
||||
distance numeric(10,2),
|
||||
duration text,
|
||||
calories_burned integer,
|
||||
activity_date timestamp without time zone NOT NULL,
|
||||
external_id character varying(100),
|
||||
raw_data character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.user_activities OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: user_photos; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_photos (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
user_id uuid,
|
||||
photo_url character varying(255) NOT NULL,
|
||||
is_main boolean DEFAULT false,
|
||||
uploaded_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
description text
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.user_photos OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: user_profiles; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_profiles (
|
||||
user_id uuid NOT NULL,
|
||||
avatar_url character varying(255),
|
||||
bio text,
|
||||
date_of_birth date,
|
||||
gender character varying(10),
|
||||
location character varying(100),
|
||||
sport_type character varying(50),
|
||||
fitness_level character varying(20),
|
||||
goals text,
|
||||
achievements text,
|
||||
total_activities integer DEFAULT 0,
|
||||
total_distance numeric(10,2) DEFAULT 0,
|
||||
total_wins integer DEFAULT 0,
|
||||
personal_records text,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
is_verified boolean,
|
||||
last_active_at date,
|
||||
CONSTRAINT user_profiles_fitness_level_check CHECK (((fitness_level)::text = ANY (ARRAY[('Beginner'::character varying)::text, ('Intermediate'::character varying)::text, ('Advanced'::character varying)::text]))),
|
||||
CONSTRAINT user_profiles_gender_check CHECK (((gender)::text = ANY (ARRAY[('Male'::character varying)::text, ('Female'::character varying)::text, ('Other'::character varying)::text])))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.user_profiles OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: users; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.users (
|
||||
id uuid DEFAULT gen_random_uuid() NOT NULL,
|
||||
email character varying(100) NOT NULL,
|
||||
phone_number character varying(15),
|
||||
encrypted_password character(60) NOT NULL,
|
||||
status bigint,
|
||||
is_first_enter boolean DEFAULT false NOT NULL,
|
||||
end_date date,
|
||||
role_id bigint NOT NULL,
|
||||
last_login date
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.users OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: verification_code; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.verification_code (
|
||||
id uuid NOT NULL,
|
||||
user_id uuid NOT NULL,
|
||||
code character varying(6) NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
expires_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.verification_code OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: event id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.event ALTER COLUMN id SET DEFAULT nextval('public.event_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_participant id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.event_participant ALTER COLUMN id SET DEFAULT nextval('public.event_participant_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: role id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.role ALTER COLUMN id SET DEFAULT nextval('public.role_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: status id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.status ALTER COLUMN id SET DEFAULT nextval('public.status_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: event; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.event (id, name, description, event_date, max_participants, organizer_id) FROM stdin;
|
||||
2 Футбол на стадионе Дружеский матч на 10 человек 2025-04-09 17:00:00 10 6b1cf72a-60b3-4f78-ac20-cfc2e75b8512
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: event_participant; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.event_participant (id, user_id, joined_at, event_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: role; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.role (id, name) FROM stdin;
|
||||
1 ADMIN
|
||||
2 USER
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: status; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.status (id, name) FROM stdin;
|
||||
1 ACTIVE
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: user_activities; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.user_activities (id, user_id, activity_type, distance, duration, calories_burned, activity_date, external_id, raw_data) FROM stdin;
|
||||
dfa160ae-d33f-4b01-8672-8168bd744ca3 960b0c25-4568-4a4a-b45a-1edf4a6dfcfc Running 5.00 PT30M 500 2025-04-05 20:03:26.558959 external-id-123 {"speed": "12km/h"}
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: user_photos; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.user_photos (id, user_id, photo_url, is_main, uploaded_at, description) FROM stdin;
|
||||
d5023ad9-591d-4a9f-9872-bf3209bc7166 960b0c25-4568-4a4a-b45a-1edf4a6dfcfc http://example.com/new-avatar.jpg t 2025-04-05 19:50:16.791349 \N
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: user_profiles; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.user_profiles (user_id, avatar_url, bio, date_of_birth, gender, location, sport_type, fitness_level, goals, achievements, total_activities, total_distance, total_wins, personal_records, created_at, updated_at, is_verified, last_active_at) FROM stdin;
|
||||
960b0c25-4568-4a4a-b45a-1edf4a6dfcfc http://example.com/avatar.jpg Bio of the user 1990-01-01 Male New Sity Outdoor Intermediate Run 5k Completed 10k 1 5.00 5 5k in 30min 2025-04-05 16:09:11.481505 2025-04-05 20:03:26.561609 t 2025-04-05
|
||||
6b1cf72a-60b3-4f78-ac20-cfc2e75b8512 http://example.com/avatar.jpg Bio of the user 1990-01-01 Male New York Outdoor Intermediate Run 5k Completed 10k 10 100.50 5 5k in 30min 2025-04-08 13:00:54.036292 2025-04-08 13:00:54.036292 t 2025-04-05
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.users (id, email, phone_number, encrypted_password, status, is_first_enter, end_date, role_id, last_login) FROM stdin;
|
||||
ce2082c5-1f56-4293-aac4-4a057c6980bc user@example.com +1234567890 $2a$10$.PC11OLxxrEH8IodYZGY2OX4T617k4qq6vbrlGN4MdQNtnJGcI5j6 1 t \N 1 \N
|
||||
960b0c25-4568-4a4a-b45a-1edf4a6dfcfc user@example1.com \N $2a$10$xYVXvwWtPQD/gqgANOVxeuMkAHK83PTcv5tm3QTM51JpAXHXP/Ake 1 f \N 1 2025-04-05
|
||||
73c398a7-6612-4764-97ec-098c5802ae97 user@example2.com \N $2a$10$8AP//1k2Son9d/JUdUU6VuwMHGK9pzoCEAMhD5ryVN2MiMP56Pv7y 1 t \N 1 2025-04-05
|
||||
1a54beaa-6290-4dbf-b18b-a3df94cc63b5 user@example4.com \N $2a$10$7E6Pt9/01D8jKK4z0i98BesuxJVVSxLbIO1VWEVkiT1jc2yH.LLAG 1 t \N 1 2025-04-05
|
||||
6b1cf72a-60b3-4f78-ac20-cfc2e75b8512 dmitry@example.com \N $2a$10$hEZdn2vPjZkCJdMDuMs.hO31SyLqbIFgCeYfFcexZFVRBQIZeJzeq 1 t \N 1 2025-04-08
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: verification_code; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.verification_code (id, user_id, code, created_at, expires_at) FROM stdin;
|
||||
3b9a4c0b-b319-4639-ba60-ad064bc4596b ce2082c5-1f56-4293-aac4-4a057c6980bc 262495 2025-03-19 15:05:26.162304 2025-03-19 15:10:26.162304
|
||||
39c31998-35f3-4e8e-aeeb-eb3c1a877a56 960b0c25-4568-4a4a-b45a-1edf4a6dfcfc 341250 2025-04-05 14:59:50.149167 2025-04-05 15:04:50.149167
|
||||
3ecd4af4-f5e4-476b-83cf-cc4906d9efc4 6b1cf72a-60b3-4f78-ac20-cfc2e75b8512 226002 2025-04-08 13:00:08.830408 2025-04-08 13:05:08.830408
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.event_id_seq', 2, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_participant_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.event_participant_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: role_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.role_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: status_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.status_id_seq', 1, false);
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_participant event_participant_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.event_participant
|
||||
ADD CONSTRAINT event_participant_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: event event_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.event
|
||||
ADD CONSTRAINT event_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: role role_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.role
|
||||
ADD CONSTRAINT role_name_key UNIQUE (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: role role_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.role
|
||||
ADD CONSTRAINT role_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: status status_name_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.status
|
||||
ADD CONSTRAINT status_name_key UNIQUE (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: status status_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.status
|
||||
ADD CONSTRAINT status_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_activities user_activities_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_activities
|
||||
ADD CONSTRAINT user_activities_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_photos user_photos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_photos
|
||||
ADD CONSTRAINT user_photos_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_profiles user_profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_profiles
|
||||
ADD CONSTRAINT user_profiles_pkey PRIMARY KEY (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: verification_code verification_code_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.verification_code
|
||||
ADD CONSTRAINT verification_code_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_user_activities_date; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_user_activities_date ON public.user_activities USING btree (activity_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_user_activities_user_id; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_user_activities_user_id ON public.user_activities USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_user_photos_user_id; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_user_photos_user_id ON public.user_photos USING btree (user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_activities trigger_update_activity_stats; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER trigger_update_activity_stats AFTER INSERT OR DELETE OR UPDATE ON public.user_activities FOR EACH ROW EXECUTE FUNCTION public.update_activity_stats();
|
||||
|
||||
|
||||
--
|
||||
-- Name: event_participant event_participant_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.event_participant
|
||||
ADD CONSTRAINT event_participant_event_id_fkey FOREIGN KEY (event_id) REFERENCES public.event(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_activities user_activities_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_activities
|
||||
ADD CONSTRAINT user_activities_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.user_profiles(user_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_photos user_photos_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_photos
|
||||
ADD CONSTRAINT user_photos_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.user_profiles(user_id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_profiles user_profiles_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_profiles
|
||||
ADD CONSTRAINT user_profiles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_role_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_role_id_fkey FOREIGN KEY (role_id) REFERENCES public.role(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_status_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_status_fkey FOREIGN KEY (status) REFERENCES public.status(id) ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,383 @@
|
||||
-- Downloaded from: https://github.com/Dmitrytsg/onectest/blob/427db1e8ecee644c8f52ea16e7b9c608f6d3c375/onecPsqlDB.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 15.7 (Homebrew)
|
||||
-- Dumped by pg_dump version 15.7 (Homebrew)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: update_statistics(); Type: FUNCTION; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.update_statistics() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
order_date DATE;
|
||||
product_category INT;
|
||||
BEGIN
|
||||
-- Извлекаем дату заказа и категорию товара
|
||||
order_date := DATE(NEW.order_time);
|
||||
SELECT category_id INTO product_category FROM products WHERE product_id = NEW.product_id;
|
||||
|
||||
-- Проверяем, существует ли запись в статистике за данный день и категорию
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM statistics
|
||||
WHERE date = order_date
|
||||
AND category_id = product_category
|
||||
) THEN
|
||||
-- Если запись существует, обновляем количество товаров
|
||||
UPDATE statistics
|
||||
SET product_count = product_count + NEW.number
|
||||
WHERE date = order_date
|
||||
AND category_id = product_category;
|
||||
ELSE
|
||||
-- Если запись не существует, создаем новую
|
||||
INSERT INTO statistics (date, category_id, product_count)
|
||||
VALUES (order_date, product_category, NEW.number);
|
||||
END IF;
|
||||
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.update_statistics() OWNER TO dmitry;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: categories; Type: TABLE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE TABLE public.categories (
|
||||
category_id integer NOT NULL,
|
||||
category_name character varying(50) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.categories OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: categories_category_id_seq; Type: SEQUENCE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.categories_category_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.categories_category_id_seq OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: categories_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.categories_category_id_seq OWNED BY public.categories.category_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders; Type: TABLE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE TABLE public.orders (
|
||||
order_id integer NOT NULL,
|
||||
order_time timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
product_id integer NOT NULL,
|
||||
number integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.orders OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: orders_order_id_seq; Type: SEQUENCE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.orders_order_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.orders_order_id_seq OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: orders_order_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.orders_order_id_seq OWNED BY public.orders.order_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: products; Type: TABLE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE TABLE public.products (
|
||||
product_id integer NOT NULL,
|
||||
product_name character varying(100) NOT NULL,
|
||||
category_id integer NOT NULL,
|
||||
price numeric(10,2) NOT NULL,
|
||||
description text
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.products OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: products_product_id_seq; Type: SEQUENCE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.products_product_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.products_product_id_seq OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: products_product_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.products_product_id_seq OWNED BY public.products.product_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: statistics; Type: TABLE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE TABLE public.statistics (
|
||||
stat_id integer NOT NULL,
|
||||
date date NOT NULL,
|
||||
category_id integer NOT NULL,
|
||||
product_count integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.statistics OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: statistics_stat_id_seq; Type: SEQUENCE; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.statistics_stat_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.statistics_stat_id_seq OWNER TO dmitry;
|
||||
|
||||
--
|
||||
-- Name: statistics_stat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.statistics_stat_id_seq OWNED BY public.statistics.stat_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories category_id; Type: DEFAULT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.categories ALTER COLUMN category_id SET DEFAULT nextval('public.categories_category_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders order_id; Type: DEFAULT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.orders ALTER COLUMN order_id SET DEFAULT nextval('public.orders_order_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: products product_id; Type: DEFAULT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.products ALTER COLUMN product_id SET DEFAULT nextval('public.products_product_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: statistics stat_id; Type: DEFAULT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.statistics ALTER COLUMN stat_id SET DEFAULT nextval('public.statistics_stat_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
COPY public.categories (category_id, category_name) FROM stdin;
|
||||
1 Electronics
|
||||
2 Books
|
||||
3 Clothing
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: orders; Type: TABLE DATA; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
COPY public.orders (order_id, order_time, product_id, number) FROM stdin;
|
||||
1 2024-06-20 15:53:18.844677 15 3
|
||||
2 2024-06-20 15:54:59.915415 14 7
|
||||
3 2024-06-20 15:54:59.915415 18 4
|
||||
4 2024-06-20 15:54:59.915415 22 10
|
||||
5 2024-06-20 15:54:59.915415 21 6
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
COPY public.products (product_id, product_name, category_id, price, description) FROM stdin;
|
||||
13 Smartphone 1 599.99 Latest model with advanced features
|
||||
14 Laptop 1 999.99 High performance laptop with 16GB RAM
|
||||
15 Headphones 1 199.99 Noise-cancelling over-ear headphones
|
||||
16 Tablet 1 299.99 10-inch tablet with high-resolution display
|
||||
17 E-reader 2 129.99 Portable e-reader with backlit display
|
||||
18 Novel 2 19.99 Bestselling fiction novel
|
||||
19 Cookbook 2 24.99 Collection of gourmet recipes
|
||||
20 Biography 2 29.99 Biography of a famous personality
|
||||
21 T-shirt 3 14.99 Cotton T-shirt with a graphic print
|
||||
22 Jeans 3 49.99 Denim jeans with a slim fit
|
||||
23 Jacket 3 89.99 Waterproof outdoor jacket
|
||||
24 Sneakers 3 74.99 Comfortable and stylish sneakers
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: statistics; Type: TABLE DATA; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
COPY public.statistics (stat_id, date, category_id, product_count) FROM stdin;
|
||||
1 2024-06-20 1 10
|
||||
2 2024-06-20 2 4
|
||||
3 2024-06-20 3 16
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories_category_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.categories_category_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders_order_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.orders_order_id_seq', 5, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: products_product_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.products_product_id_seq', 24, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: statistics_stat_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.statistics_stat_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: categories categories_pkey; Type: CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.categories
|
||||
ADD CONSTRAINT categories_pkey PRIMARY KEY (category_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders orders_pkey; Type: CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.orders
|
||||
ADD CONSTRAINT orders_pkey PRIMARY KEY (order_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: products products_pkey; Type: CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.products
|
||||
ADD CONSTRAINT products_pkey PRIMARY KEY (product_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: statistics statistics_pkey; Type: CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.statistics
|
||||
ADD CONSTRAINT statistics_pkey PRIMARY KEY (stat_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders after_order_insert; Type: TRIGGER; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
CREATE TRIGGER after_order_insert AFTER INSERT ON public.orders FOR EACH ROW EXECUTE FUNCTION public.update_statistics();
|
||||
|
||||
|
||||
--
|
||||
-- Name: products fk_category_id; Type: FK CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.products
|
||||
ADD CONSTRAINT fk_category_id FOREIGN KEY (category_id) REFERENCES public.categories(category_id) ON UPDATE SET NULL ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- Name: statistics fk_category_id; Type: FK CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.statistics
|
||||
ADD CONSTRAINT fk_category_id FOREIGN KEY (category_id) REFERENCES public.categories(category_id) ON UPDATE SET NULL ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- Name: orders fk_product_id; Type: FK CONSTRAINT; Schema: public; Owner: dmitry
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.orders
|
||||
ADD CONSTRAINT fk_product_id FOREIGN KEY (product_id) REFERENCES public.products(product_id) ON UPDATE SET NULL ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,613 @@
|
||||
-- Downloaded from: https://github.com/KangAbbad/laundry-app/blob/78b2c9c3724451e0c767014489eb3c101ef2dc3c/dump_.sql
|
||||
--
|
||||
-- PostgreSQL database cluster dump
|
||||
--
|
||||
|
||||
SET default_transaction_read_only = off;
|
||||
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
|
||||
--
|
||||
-- Drop databases (except postgres and template1)
|
||||
--
|
||||
|
||||
DROP DATABASE laundryapp;
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Drop roles
|
||||
--
|
||||
|
||||
DROP ROLE postgres;
|
||||
|
||||
|
||||
--
|
||||
-- Roles
|
||||
--
|
||||
|
||||
CREATE ROLE postgres;
|
||||
ALTER ROLE postgres WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS PASSWORD 'SCRAM-SHA-256$4096:I68tB9pBDKM3OrgkD7901A==$hYxpQVMe6Tg+8NrcWCU/8zj/ZV8iin7CZjzT7QN1oUQ=:o+IZGdW7ixEUWk2NysrLj4xA/fHD31yIahmgdmmmkXY=';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- Databases
|
||||
--
|
||||
|
||||
--
|
||||
-- Database "template1" dump
|
||||
--
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
-- Dumped by pg_dump version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
UPDATE pg_catalog.pg_database SET datistemplate = false WHERE datname = 'template1';
|
||||
DROP DATABASE template1;
|
||||
--
|
||||
-- Name: template1; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE template1 WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE = 'en_US.utf8';
|
||||
|
||||
|
||||
ALTER DATABASE template1 OWNER TO postgres;
|
||||
|
||||
\connect template1
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: DATABASE template1; Type: COMMENT; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
COMMENT ON DATABASE template1 IS 'default template for new databases';
|
||||
|
||||
|
||||
--
|
||||
-- Name: template1; Type: DATABASE PROPERTIES; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER DATABASE template1 IS_TEMPLATE = true;
|
||||
|
||||
|
||||
\connect template1
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: DATABASE template1; Type: ACL; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
REVOKE CONNECT,TEMPORARY ON DATABASE template1 FROM PUBLIC;
|
||||
GRANT CONNECT ON DATABASE template1 TO PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
--
|
||||
-- Database "laundryapp" dump
|
||||
--
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
-- Dumped by pg_dump version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: laundryapp; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE laundryapp WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE = 'en_US.utf8';
|
||||
|
||||
|
||||
ALTER DATABASE laundryapp OWNER TO postgres;
|
||||
|
||||
\connect laundryapp
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: today_revenue(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.today_revenue() RETURNS TABLE(admin_id bigint, total_revenue numeric)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
begin
|
||||
return query select t.admin_id, sum(t.total_price) as total_revenue from transactions t where date(created_at) = current_date group by t.admin_id;
|
||||
end
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.today_revenue() OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: admin_roles; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.admin_roles (
|
||||
admin_id bigint NOT NULL,
|
||||
role_id bigint NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.admin_roles OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: admins; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.admins (
|
||||
id bigint NOT NULL,
|
||||
address character varying(255),
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
email character varying(255) NOT NULL,
|
||||
id_card character varying(255),
|
||||
name character varying(255),
|
||||
password character varying(255),
|
||||
phone character varying(255) NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
username character varying(255) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.admins OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: admins_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.admins_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.admins_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: admins_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.admins_id_seq OWNED BY public.admins.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: roles; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.roles (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
name character varying(60),
|
||||
updated_at timestamp without time zone NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.roles OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: roles_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.roles_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.roles_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: roles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.roles_id_seq OWNED BY public.roles.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: summary_revenue; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.summary_revenue (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
total_revenue numeric(19,2),
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
admin_id bigint
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.summary_revenue OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: summary_revenue_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.summary_revenue_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.summary_revenue_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: summary_revenue_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.summary_revenue_id_seq OWNED BY public.summary_revenue.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: transactions; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.transactions (
|
||||
id bigint NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
notes text,
|
||||
status integer,
|
||||
total_price numeric(19,2),
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
weight integer NOT NULL,
|
||||
admin_id bigint
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.transactions OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: transactions_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.transactions_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.transactions_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: transactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.transactions_id_seq OWNED BY public.transactions.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins ALTER COLUMN id SET DEFAULT nextval('public.admins_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: roles id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.roles ALTER COLUMN id SET DEFAULT nextval('public.roles_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: summary_revenue id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.summary_revenue ALTER COLUMN id SET DEFAULT nextval('public.summary_revenue_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: transactions id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.transactions ALTER COLUMN id SET DEFAULT nextval('public.transactions_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: admin_roles; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.admin_roles (admin_id, role_id) FROM stdin;
|
||||
1 1
|
||||
2 1
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: admins; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.admins (id, address, created_at, email, id_card, name, password, phone, updated_at, username) FROM stdin;
|
||||
1 Laweyan, Solo 2022-09-12 09:57:01.477 email1@email.com 3333123456789 User 01 $2a$10$Cs3WOQOCwA/3LznT89HzAOF7eZevbWpI5/k1diqZ7swM5OQOOe3ai 08123456789 2022-09-12 09:57:01.477 user01
|
||||
2 Laweyan, Solo 2022-09-12 12:29:47.912 email2@email.com 333312345678910 User 02 $2a$10$ioACrSPTM8ZT1AOYfQiT/.3tL.swZ.f7nfz/iZs996bpDXAxrUOiS 0812345678910 2022-09-12 12:29:47.912 user02
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: roles; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.roles (id, created_at, name, updated_at) FROM stdin;
|
||||
1 2022-09-12 09:47:52.930144 ROLE_ADMIN 2022-09-12 09:47:52.930144
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: summary_revenue; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.summary_revenue (id, created_at, total_revenue, updated_at, admin_id) FROM stdin;
|
||||
1 2022-09-12 12:18:12.169 45000.00 2022-09-12 18:45:54.121 1
|
||||
2 2022-09-12 12:30:00.031 30000.00 2022-09-12 18:45:54.124 2
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: transactions; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.transactions (id, created_at, notes, status, total_price, updated_at, weight, admin_id) FROM stdin;
|
||||
1 2022-09-12 09:57:32.101 Transaksi 1 Admin 1 0 15000.00 2022-09-12 09:57:32.101 3 1
|
||||
2 2022-09-12 11:19:18.994 Transaksi 2 Admin 1 0 15000.00 2022-09-12 11:19:18.994 3 1
|
||||
3 2022-09-12 12:10:02.213 Transaksi 3 Admin 1 0 15000.00 2022-09-12 12:10:02.213 3 1
|
||||
4 2022-09-12 12:29:57.164 Transaksi 1 Admin 2 0 15000.00 2022-09-12 12:29:57.164 3 2
|
||||
5 2022-09-12 12:31:07.836 Transaksi 2 Admin 2 0 15000.00 2022-09-12 12:31:07.836 3 2
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.admins_id_seq', 2, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: roles_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.roles_id_seq', 1, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: summary_revenue_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.summary_revenue_id_seq', 2, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: transactions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.transactions_id_seq', 5, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admin_roles admin_roles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admin_roles
|
||||
ADD CONSTRAINT admin_roles_pkey PRIMARY KEY (admin_id, role_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins admins_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins
|
||||
ADD CONSTRAINT admins_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: roles roles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.roles
|
||||
ADD CONSTRAINT roles_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: summary_revenue summary_revenue_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.summary_revenue
|
||||
ADD CONSTRAINT summary_revenue_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: transactions transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.transactions
|
||||
ADD CONSTRAINT transactions_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins uk_40k3ldiov4eh6w3vk8046lic; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins
|
||||
ADD CONSTRAINT uk_40k3ldiov4eh6w3vk8046lic UNIQUE (email, phone, username);
|
||||
|
||||
|
||||
--
|
||||
-- Name: roles uk_nb4h0p6txrmfc0xbrd1kglp9t; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.roles
|
||||
ADD CONSTRAINT uk_nb4h0p6txrmfc0xbrd1kglp9t UNIQUE (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admin_roles fk3liyab508sfblqps0eqjhmjqk; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admin_roles
|
||||
ADD CONSTRAINT fk3liyab508sfblqps0eqjhmjqk FOREIGN KEY (role_id) REFERENCES public.roles(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: transactions fkcld5louxmdqxvivbradq5g23r; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.transactions
|
||||
ADD CONSTRAINT fkcld5louxmdqxvivbradq5g23r FOREIGN KEY (admin_id) REFERENCES public.admins(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admin_roles fkghcw89q6jebq3c6kocnobjusr; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admin_roles
|
||||
ADD CONSTRAINT fkghcw89q6jebq3c6kocnobjusr FOREIGN KEY (admin_id) REFERENCES public.admins(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: summary_revenue fksg88fdt3bygok7vqpdeno6jly; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.summary_revenue
|
||||
ADD CONSTRAINT fksg88fdt3bygok7vqpdeno6jly FOREIGN KEY (admin_id) REFERENCES public.admins(id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
--
|
||||
-- Database "postgres" dump
|
||||
--
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
-- Dumped by pg_dump version 14.5 (Debian 14.5-1.pgdg110+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
DROP DATABASE postgres;
|
||||
--
|
||||
-- Name: postgres; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE postgres WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE = 'en_US.utf8';
|
||||
|
||||
|
||||
ALTER DATABASE postgres OWNER TO postgres;
|
||||
|
||||
\connect postgres
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: DATABASE postgres; Type: COMMENT; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
COMMENT ON DATABASE postgres IS 'default administrative connection database';
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
--
|
||||
-- PostgreSQL database cluster dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,480 @@
|
||||
-- Downloaded from: https://github.com/Mistral-war2ru/PG-connect/blob/ba0e4f62b6b9b5799cf645fdc072d59f727b9ffe/lab9/TestDB.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 15.2
|
||||
-- Dumped by pg_dump version 15.2
|
||||
|
||||
-- Started on 2023-04-19 19:40:00
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 3370 (class 1262 OID 25411)
|
||||
-- Name: StudentsDB; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE "StudentsDB" WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'Russian_Russia.1251';
|
||||
|
||||
|
||||
ALTER DATABASE "StudentsDB" OWNER TO postgres;
|
||||
|
||||
\connect "StudentsDB"
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 3371 (class 0 OID 0)
|
||||
-- Name: StudentsDB; Type: DATABASE PROPERTIES; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER ROLE postgres IN DATABASE "StudentsDB" SET effective_cache_size TO '65536';
|
||||
|
||||
|
||||
\connect "StudentsDB"
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1255 OID 25412)
|
||||
-- Name: get_fiit_2019(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.get_fiit_2019() RETURNS text
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
declare
|
||||
ret text default '';
|
||||
rec record;
|
||||
curs refcursor;
|
||||
begin
|
||||
--call proc1(curs, 2019, 'ФИИТ');
|
||||
call proc1(curs, 2018, 'ФИИТ');
|
||||
loop
|
||||
fetch curs into rec;
|
||||
exit when not found;
|
||||
ret := ret || '{' || rec.SpecialtyName || ',' || rec.SetName|| ',' || rec.GroupName || ',' || rec.SetYear|| '}';
|
||||
end loop;
|
||||
close curs;
|
||||
return ret;
|
||||
end; $$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.get_fiit_2019() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1255 OID 25413)
|
||||
-- Name: proc1(refcursor); Type: PROCEDURE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE PROCEDURE public.proc1(INOUT curs refcursor)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
lcurs refcursor;
|
||||
BEGIN
|
||||
open lcurs for
|
||||
select SpecialtyName, SetName, GroupName, SetYear
|
||||
from Groups inner join (Sets inner join Specialities on Sets.SpecialtyID = Specialities.SpecialtyID) on Sets.SetID = Groups.SetID
|
||||
where Sets.SetYear = 2019 AND Specialities.SpecialtyCode = 'ФИИТ';
|
||||
curs = lcurs;
|
||||
END $$;
|
||||
|
||||
|
||||
ALTER PROCEDURE public.proc1(INOUT curs refcursor) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1255 OID 25414)
|
||||
-- Name: proc1(refcursor, integer, text); Type: PROCEDURE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE PROCEDURE public.proc1(INOUT curs refcursor, IN yr integer, IN spec text)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
lcurs refcursor;
|
||||
BEGIN
|
||||
open lcurs for
|
||||
select SpecialtyName, SetName, GroupName, SetYear
|
||||
from Groups inner join (Sets inner join Specialities on Sets.SpecialtyID = Specialities.SpecialtyID) on Sets.SetID = Groups.SetID
|
||||
where Sets.SetYear = yr AND Specialities.SpecialtyCode = spec;
|
||||
curs = lcurs;
|
||||
END $$;
|
||||
|
||||
|
||||
ALTER PROCEDURE public.proc1(INOUT curs refcursor, IN yr integer, IN spec text) OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 214 (class 1259 OID 25415)
|
||||
-- Name: groups; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.groups (
|
||||
groupid integer NOT NULL,
|
||||
setid integer NOT NULL,
|
||||
groupname text NOT NULL,
|
||||
teachformid integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.groups OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 215 (class 1259 OID 25420)
|
||||
-- Name: groups_groupid_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.groups ALTER COLUMN groupid ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.groups_groupid_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 25462)
|
||||
-- Name: labs; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.labs (
|
||||
"ID" integer NOT NULL,
|
||||
"Name" text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.labs OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 25469)
|
||||
-- Name: labs_ID_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.labs ALTER COLUMN "ID" ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public."labs_ID_seq"
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 216 (class 1259 OID 25421)
|
||||
-- Name: sets; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.sets (
|
||||
setid integer NOT NULL,
|
||||
setname text NOT NULL,
|
||||
setyear integer NOT NULL,
|
||||
specialtyid integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.sets OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 25426)
|
||||
-- Name: sets_setid_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.sets ALTER COLUMN setid ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.sets_setid_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 25427)
|
||||
-- Name: specialities; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.specialities (
|
||||
specialtyid integer NOT NULL,
|
||||
specialtyname text NOT NULL,
|
||||
specialtycode text NOT NULL,
|
||||
descript text
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.specialities OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 25432)
|
||||
-- Name: specialities_specialtyid_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.specialities ALTER COLUMN specialtyid ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.specialities_specialtyid_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 25458)
|
||||
-- Name: v1; Type: VIEW; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE VIEW public.v1 AS
|
||||
SELECT groups.groupname,
|
||||
sets.setname,
|
||||
sets.setyear,
|
||||
specialities.specialtycode
|
||||
FROM (public.groups
|
||||
JOIN (public.sets
|
||||
JOIN public.specialities ON ((specialities.specialtyid = sets.specialtyid))) ON ((sets.setid = groups.setid)));
|
||||
|
||||
|
||||
ALTER TABLE public.v1 OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 3357 (class 0 OID 25415)
|
||||
-- Dependencies: 214
|
||||
-- Data for Name: groups; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (3, 2, 'ПИ-20-а', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (4, 2, 'ПИ-20-б', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (7, 4, 'ФИИТ-16-а', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (8, 4, 'ФИИТ-16-б', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (9, 5, 'ФИИТ-18-а', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (10, 5, 'ФИИТ-18-б', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (12, 6, 'ФИИТ-20-а', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (13, 6, 'ФИИТ-20-б', 1);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (11, 5, 'ФИИТ-18-в', 2);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (14, 6, 'ФИИТ-20-в', 2);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (15, 1, 'ПМ-20-1', 2);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (16, 1, 'ПМ-20-2', 2);
|
||||
INSERT INTO public.groups OVERRIDING SYSTEM VALUE VALUES (18, 2, 'test', 2);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3363 (class 0 OID 25462)
|
||||
-- Dependencies: 221
|
||||
-- Data for Name: labs; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.labs OVERRIDING SYSTEM VALUE VALUES (1, 'lab1');
|
||||
INSERT INTO public.labs OVERRIDING SYSTEM VALUE VALUES (2, 'lab2');
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3359 (class 0 OID 25421)
|
||||
-- Dependencies: 216
|
||||
-- Data for Name: sets; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (1, 'ПИ-15', 2015, 1);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (2, 'ПИ-20', 2020, 2);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (3, 'ФИИТ-15', 2015, 3);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (4, 'ФИИТ-16', 2016, 3);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (5, 'ФИИТ-18', 2018, 3);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (6, 'ФИИТ-20', 2019, 3);
|
||||
INSERT INTO public.sets OVERRIDING SYSTEM VALUE VALUES (7, 'name12', 2016, 10);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3361 (class 0 OID 25427)
|
||||
-- Dependencies: 218
|
||||
-- Data for Name: specialities; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
INSERT INTO public.specialities OVERRIDING SYSTEM VALUE VALUES (3, 'Фундаментальная информатика и ИТ', 'ФИИТ', 'Кафедра ВТ');
|
||||
INSERT INTO public.specialities OVERRIDING SYSTEM VALUE VALUES (1, 'Прикладная информатика', 'ПИ', 'Кафедра ПМИ');
|
||||
INSERT INTO public.specialities OVERRIDING SYSTEM VALUE VALUES (2, 'Прикладная математика и информатика', 'ПМИ', 'Кафедра ПМИ');
|
||||
INSERT INTO public.specialities OVERRIDING SYSTEM VALUE VALUES (10, 'test1', 'test2', 'test3');
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3372 (class 0 OID 0)
|
||||
-- Dependencies: 215
|
||||
-- Name: groups_groupid_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.groups_groupid_seq', 18, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3373 (class 0 OID 0)
|
||||
-- Dependencies: 222
|
||||
-- Name: labs_ID_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public."labs_ID_seq"', 10, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3374 (class 0 OID 0)
|
||||
-- Dependencies: 217
|
||||
-- Name: sets_setid_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.sets_setid_seq', 7, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3375 (class 0 OID 0)
|
||||
-- Dependencies: 219
|
||||
-- Name: specialities_specialtyid_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.specialities_specialtyid_seq', 10, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3196 (class 2606 OID 25434)
|
||||
-- Name: groups groups_groupid_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.groups
|
||||
ADD CONSTRAINT groups_groupid_key UNIQUE (groupid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3211 (class 2606 OID 25468)
|
||||
-- Name: labs labs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.labs
|
||||
ADD CONSTRAINT labs_pkey PRIMARY KEY ("ID");
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3199 (class 2606 OID 25436)
|
||||
-- Name: groups pkgroups; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.groups
|
||||
ADD CONSTRAINT pkgroups PRIMARY KEY (groupid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3202 (class 2606 OID 25438)
|
||||
-- Name: sets pksets; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.sets
|
||||
ADD CONSTRAINT pksets PRIMARY KEY (setid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3206 (class 2606 OID 25440)
|
||||
-- Name: specialities pkspecialities; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.specialities
|
||||
ADD CONSTRAINT pkspecialities PRIMARY KEY (specialtyid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3204 (class 2606 OID 25442)
|
||||
-- Name: sets sets_setid_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.sets
|
||||
ADD CONSTRAINT sets_setid_key UNIQUE (setid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3208 (class 2606 OID 25444)
|
||||
-- Name: specialities specialities_specialtyid_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.specialities
|
||||
ADD CONSTRAINT specialities_specialtyid_key UNIQUE (specialtyid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3197 (class 1259 OID 25445)
|
||||
-- Name: igroupsteachformid; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX igroupsteachformid ON public.groups USING btree (teachformid);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3200 (class 1259 OID 25446)
|
||||
-- Name: isetssetyear; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX isetssetyear ON public.sets USING btree (setyear);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3209 (class 1259 OID 25447)
|
||||
-- Name: specialtyindex; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX specialtyindex ON public.specialities USING btree (specialtyid);
|
||||
|
||||
ALTER TABLE public.specialities CLUSTER ON specialtyindex;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3212 (class 2606 OID 25448)
|
||||
-- Name: groups fkgroupssets; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.groups
|
||||
ADD CONSTRAINT fkgroupssets FOREIGN KEY (setid) REFERENCES public.sets(setid) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3213 (class 2606 OID 25453)
|
||||
-- Name: sets fksetsspecialities; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.sets
|
||||
ADD CONSTRAINT fksetsspecialities FOREIGN KEY (specialtyid) REFERENCES public.specialities(specialtyid) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
-- Completed on 2023-04-19 19:40:00
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,724 @@
|
||||
-- Downloaded from: https://github.com/TaraPadilla/MarketSpring/blob/84bf503f29fa1db3c3f4ee5acfdb7bbb59fd0f39/docs/bdmarket.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.4
|
||||
-- Dumped by pg_dump version 16.4
|
||||
|
||||
-- Started on 2024-08-26 18:11:04
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 6 (class 2615 OID 16595)
|
||||
-- Name: base; Type: SCHEMA; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SCHEMA base;
|
||||
|
||||
|
||||
ALTER SCHEMA base OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 9 (class 2615 OID 17248)
|
||||
-- Name: comercial; Type: SCHEMA; Schema: -; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE SCHEMA comercial;
|
||||
|
||||
|
||||
ALTER SCHEMA comercial OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 7 (class 2615 OID 16596)
|
||||
-- Name: products; Type: SCHEMA; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SCHEMA products;
|
||||
|
||||
|
||||
ALTER SCHEMA products OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 8 (class 2615 OID 16597)
|
||||
-- Name: services; Type: SCHEMA; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SCHEMA services;
|
||||
|
||||
|
||||
ALTER SCHEMA services OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 16505)
|
||||
-- Name: clientes; Type: TABLE; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE base.clientes (
|
||||
id character varying(255) NOT NULL,
|
||||
nombre character varying(255),
|
||||
apellidos character varying(255),
|
||||
celular double precision,
|
||||
direccion character varying(255),
|
||||
correo_electronico character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE base.clientes OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1259 OID 16514)
|
||||
-- Name: compras; Type: TABLE; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE base.compras (
|
||||
id_compra integer NOT NULL,
|
||||
id_cliente character varying(255) NOT NULL,
|
||||
fecha timestamp without time zone,
|
||||
medio_pago character varying(1),
|
||||
comentario character varying(255),
|
||||
estado character varying(1)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE base.compras OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 227 (class 1259 OID 16519)
|
||||
-- Name: compras_id_compra_seq; Type: SEQUENCE; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE SEQUENCE base.compras_id_compra_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE base.compras_id_compra_seq OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 4943 (class 0 OID 0)
|
||||
-- Dependencies: 227
|
||||
-- Name: compras_id_compra_seq; Type: SEQUENCE OWNED BY; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER SEQUENCE base.compras_id_compra_seq OWNED BY base.compras.id_compra;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 236 (class 1259 OID 16841)
|
||||
-- Name: empresa; Type: TABLE; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE base.empresa (
|
||||
id_empresa integer NOT NULL,
|
||||
nombre character varying(255) NOT NULL,
|
||||
descripcion character varying NOT NULL,
|
||||
estado boolean DEFAULT true
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE base.empresa OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 235 (class 1259 OID 16840)
|
||||
-- Name: empresa_id_empresa_seq; Type: SEQUENCE; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE base.empresa ALTER COLUMN id_empresa ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME base.empresa_id_empresa_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 240 (class 1259 OID 17407)
|
||||
-- Name: usuario; Type: TABLE; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE base.usuario (
|
||||
id_usuario integer NOT NULL,
|
||||
id_empresa integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE base.usuario OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 229 (class 1259 OID 16523)
|
||||
-- Name: cotizacion; Type: TABLE; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE comercial.cotizacion (
|
||||
id_cotizacion integer NOT NULL,
|
||||
estado character varying(255) NOT NULL,
|
||||
fecha_creacion timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
notas character varying(255),
|
||||
precio_total numeric(6,2) NOT NULL,
|
||||
id_catalogo integer,
|
||||
id_servicio integer,
|
||||
id_usuario integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE comercial.cotizacion OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 230 (class 1259 OID 16529)
|
||||
-- Name: cotizacion_id_cotizacion_seq; Type: SEQUENCE; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE comercial.cotizacion ALTER COLUMN id_cotizacion ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME comercial.cotizacion_id_cotizacion_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 238 (class 1259 OID 17156)
|
||||
-- Name: catalogo; Type: TABLE; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE products.catalogo (
|
||||
id_catalogo integer NOT NULL,
|
||||
id_empresa integer,
|
||||
nombre character varying(255) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE products.catalogo OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 237 (class 1259 OID 17155)
|
||||
-- Name: catalogo_id_catalogo_seq; Type: SEQUENCE; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE products.catalogo ALTER COLUMN id_catalogo ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME products.catalogo_id_catalogo_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 239 (class 1259 OID 17392)
|
||||
-- Name: catalogo_productos; Type: TABLE; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE products.catalogo_productos (
|
||||
id_catalogo integer NOT NULL,
|
||||
id_producto integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE products.catalogo_productos OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 16501)
|
||||
-- Name: categorias; Type: TABLE; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE products.categorias (
|
||||
id_categoria integer NOT NULL,
|
||||
descripcion character varying(255) NOT NULL,
|
||||
estado boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE products.categorias OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 16504)
|
||||
-- Name: categorias_id_categoria_seq; Type: SEQUENCE; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE SEQUENCE products.categorias_id_categoria_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE products.categorias_id_categoria_seq OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 4944 (class 0 OID 0)
|
||||
-- Dependencies: 222
|
||||
-- Name: categorias_id_categoria_seq; Type: SEQUENCE OWNED BY; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER SEQUENCE products.categorias_id_categoria_seq OWNED BY products.categorias.id_categoria;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 228 (class 1259 OID 16520)
|
||||
-- Name: compras_productos; Type: TABLE; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE products.compras_productos (
|
||||
id_compra integer NOT NULL,
|
||||
id_producto integer NOT NULL,
|
||||
cantidad integer,
|
||||
total numeric(38,2),
|
||||
estado boolean
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE products.compras_productos OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 231 (class 1259 OID 16530)
|
||||
-- Name: productos; Type: TABLE; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE products.productos (
|
||||
id_producto integer NOT NULL,
|
||||
nombre character varying(255),
|
||||
id_categoria integer NOT NULL,
|
||||
codigo_barras character varying(255),
|
||||
precio_venta numeric(38,2),
|
||||
cantidad_stock integer NOT NULL,
|
||||
estado boolean
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE products.productos OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 232 (class 1259 OID 16535)
|
||||
-- Name: productos_id_producto_seq; Type: SEQUENCE; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE SEQUENCE products.productos_id_producto_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE products.productos_id_producto_seq OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 4945 (class 0 OID 0)
|
||||
-- Dependencies: 232
|
||||
-- Name: productos_id_producto_seq; Type: SEQUENCE OWNED BY; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER SEQUENCE products.productos_id_producto_seq OWNED BY products.productos.id_producto;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 16497)
|
||||
-- Name: caracteristica; Type: TABLE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE services.caracteristica (
|
||||
id_caracteristica integer NOT NULL,
|
||||
descripcion character varying(255) NOT NULL,
|
||||
nombre character varying(50) NOT NULL,
|
||||
id_servicio integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE services.caracteristica OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 16500)
|
||||
-- Name: caracteristica_id_caracteristica_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE services.caracteristica ALTER COLUMN id_caracteristica ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME services.caracteristica_id_caracteristica_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1259 OID 16510)
|
||||
-- Name: componente; Type: TABLE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE services.componente (
|
||||
id_componente integer NOT NULL,
|
||||
descripcion character varying(255) NOT NULL,
|
||||
nombre character varying(50) NOT NULL,
|
||||
precio numeric(6,2) NOT NULL,
|
||||
id_servicio integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE services.componente OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1259 OID 16513)
|
||||
-- Name: componente_id_componente_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE services.componente ALTER COLUMN id_componente ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME services.componente_id_componente_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 233 (class 1259 OID 16536)
|
||||
-- Name: servicio; Type: TABLE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
CREATE TABLE services.servicio (
|
||||
id_servicio integer NOT NULL,
|
||||
descripcion character varying(150) NOT NULL,
|
||||
nombre_servicio character varying(30) NOT NULL,
|
||||
visible boolean NOT NULL,
|
||||
id_empresa integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE services.servicio OWNER TO ebroot;
|
||||
|
||||
--
|
||||
-- TOC entry 4946 (class 0 OID 0)
|
||||
-- Dependencies: 233
|
||||
-- Name: COLUMN servicio.id_empresa; Type: COMMENT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
COMMENT ON COLUMN services.servicio.id_empresa IS 'Empresa que presta este servicio';
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 234 (class 1259 OID 16539)
|
||||
-- Name: servicio_id_cotizacion_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE services.servicio ALTER COLUMN id_servicio ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME services.servicio_id_cotizacion_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4749 (class 2604 OID 16541)
|
||||
-- Name: compras id_compra; Type: DEFAULT; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.compras ALTER COLUMN id_compra SET DEFAULT nextval('base.compras_id_compra_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4748 (class 2604 OID 16540)
|
||||
-- Name: categorias id_categoria; Type: DEFAULT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.categorias ALTER COLUMN id_categoria SET DEFAULT nextval('products.categorias_id_categoria_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4751 (class 2604 OID 16542)
|
||||
-- Name: productos id_producto; Type: DEFAULT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.productos ALTER COLUMN id_producto SET DEFAULT nextval('products.productos_id_producto_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4758 (class 2606 OID 16548)
|
||||
-- Name: clientes clientes_pkey; Type: CONSTRAINT; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.clientes
|
||||
ADD CONSTRAINT clientes_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4762 (class 2606 OID 16552)
|
||||
-- Name: compras compras_pkey; Type: CONSTRAINT; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.compras
|
||||
ADD CONSTRAINT compras_pkey PRIMARY KEY (id_compra);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4774 (class 2606 OID 16848)
|
||||
-- Name: empresa pk_empresa; Type: CONSTRAINT; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.empresa
|
||||
ADD CONSTRAINT pk_empresa PRIMARY KEY (id_empresa);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4780 (class 2606 OID 17416)
|
||||
-- Name: usuario unq_usuario_id_usuario; Type: CONSTRAINT; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.usuario
|
||||
ADD CONSTRAINT unq_usuario_id_usuario UNIQUE (id_usuario);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4766 (class 2606 OID 16556)
|
||||
-- Name: cotizacion cotizacion_pkey; Type: CONSTRAINT; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY comercial.cotizacion
|
||||
ADD CONSTRAINT cotizacion_pkey PRIMARY KEY (id_cotizacion);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4756 (class 2606 OID 16546)
|
||||
-- Name: categorias categorias_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.categorias
|
||||
ADD CONSTRAINT categorias_pkey PRIMARY KEY (id_categoria);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4764 (class 2606 OID 16554)
|
||||
-- Name: compras_productos compras_productos_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.compras_productos
|
||||
ADD CONSTRAINT compras_productos_pkey PRIMARY KEY (id_compra, id_producto);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4776 (class 2606 OID 17160)
|
||||
-- Name: catalogo pk_catalogo; Type: CONSTRAINT; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.catalogo
|
||||
ADD CONSTRAINT pk_catalogo PRIMARY KEY (id_catalogo);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4768 (class 2606 OID 16558)
|
||||
-- Name: productos productos_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.productos
|
||||
ADD CONSTRAINT productos_pkey PRIMARY KEY (id_producto);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4778 (class 2606 OID 17396)
|
||||
-- Name: catalogo_productos unq_catalogo_productos_id_catalogo; Type: CONSTRAINT; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.catalogo_productos
|
||||
ADD CONSTRAINT unq_catalogo_productos_id_catalogo UNIQUE (id_catalogo);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4754 (class 2606 OID 16544)
|
||||
-- Name: caracteristica caracteristica_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.caracteristica
|
||||
ADD CONSTRAINT caracteristica_pkey PRIMARY KEY (id_caracteristica);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4760 (class 2606 OID 16550)
|
||||
-- Name: componente componente_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.componente
|
||||
ADD CONSTRAINT componente_pkey PRIMARY KEY (id_componente);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4770 (class 2606 OID 16560)
|
||||
-- Name: servicio servicio_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.servicio
|
||||
ADD CONSTRAINT servicio_pkey PRIMARY KEY (id_servicio);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4772 (class 2606 OID 16562)
|
||||
-- Name: servicio ukngllnswut8q6wwg87y95egn41; Type: CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.servicio
|
||||
ADD CONSTRAINT ukngllnswut8q6wwg87y95egn41 UNIQUE (nombre_servicio);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4783 (class 2606 OID 16563)
|
||||
-- Name: compras fk_COMPRAS_CLIENTES1; Type: FK CONSTRAINT; Schema: base; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.compras
|
||||
ADD CONSTRAINT "fk_COMPRAS_CLIENTES1" FOREIGN KEY (id_cliente) REFERENCES base.clientes(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4794 (class 2606 OID 17410)
|
||||
-- Name: usuario fk_usuario_empresa; Type: FK CONSTRAINT; Schema: base; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY base.usuario
|
||||
ADD CONSTRAINT fk_usuario_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4786 (class 2606 OID 17194)
|
||||
-- Name: cotizacion fk_cotizacion_catalogo; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY comercial.cotizacion
|
||||
ADD CONSTRAINT fk_cotizacion_catalogo FOREIGN KEY (id_catalogo) REFERENCES products.catalogo(id_catalogo);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4787 (class 2606 OID 17199)
|
||||
-- Name: cotizacion fk_cotizacion_servicio; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY comercial.cotizacion
|
||||
ADD CONSTRAINT fk_cotizacion_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4788 (class 2606 OID 17417)
|
||||
-- Name: cotizacion fk_cotizacion_usuario; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY comercial.cotizacion
|
||||
ADD CONSTRAINT fk_cotizacion_usuario FOREIGN KEY (id_usuario) REFERENCES base.usuario(id_usuario);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4784 (class 2606 OID 16568)
|
||||
-- Name: compras_productos fk_COMPRAS_PRODUCTOS_COMPRAS1; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.compras_productos
|
||||
ADD CONSTRAINT "fk_COMPRAS_PRODUCTOS_COMPRAS1" FOREIGN KEY (id_compra) REFERENCES base.compras(id_compra);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4785 (class 2606 OID 16573)
|
||||
-- Name: compras_productos fk_COMPRAS_PRODUCTOS_PRODUCTOS1; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.compras_productos
|
||||
ADD CONSTRAINT "fk_COMPRAS_PRODUCTOS_PRODUCTOS1" FOREIGN KEY (id_producto) REFERENCES products.productos(id_producto);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4789 (class 2606 OID 16578)
|
||||
-- Name: productos fk_PRODUCTOS_CATEGORIAS; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.productos
|
||||
ADD CONSTRAINT "fk_PRODUCTOS_CATEGORIAS" FOREIGN KEY (id_categoria) REFERENCES products.categorias(id_categoria);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4791 (class 2606 OID 17397)
|
||||
-- Name: catalogo fk_catalogo_catalogo_productos; Type: FK CONSTRAINT; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.catalogo
|
||||
ADD CONSTRAINT fk_catalogo_catalogo_productos FOREIGN KEY (id_catalogo) REFERENCES products.catalogo_productos(id_catalogo);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4792 (class 2606 OID 17161)
|
||||
-- Name: catalogo fk_catalogo_empresa; Type: FK CONSTRAINT; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.catalogo
|
||||
ADD CONSTRAINT fk_catalogo_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa) ON UPDATE RESTRICT ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4793 (class 2606 OID 17402)
|
||||
-- Name: catalogo_productos fk_catalogo_productos_productos; Type: FK CONSTRAINT; Schema: products; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY products.catalogo_productos
|
||||
ADD CONSTRAINT fk_catalogo_productos_productos FOREIGN KEY (id_producto) REFERENCES products.productos(id_producto);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4781 (class 2606 OID 16859)
|
||||
-- Name: caracteristica fk_caracteristica_servicio; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.caracteristica
|
||||
ADD CONSTRAINT fk_caracteristica_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio) ON UPDATE RESTRICT ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4782 (class 2606 OID 16864)
|
||||
-- Name: componente fk_componente_servicio; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.componente
|
||||
ADD CONSTRAINT fk_componente_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio) ON UPDATE RESTRICT ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4790 (class 2606 OID 16854)
|
||||
-- Name: servicio fk_servicio_empresa; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY services.servicio
|
||||
ADD CONSTRAINT fk_servicio_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa) ON UPDATE RESTRICT ON DELETE RESTRICT;
|
||||
|
||||
|
||||
-- Completed on 2024-08-26 18:11:04
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
-- Downloaded from: https://github.com/Timovski/Co-opMinesweeper/blob/c5db38d9c758b7121c0fc01e0bfedead718e709c/db.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 11.1
|
||||
-- Dumped by pg_dump version 11.1
|
||||
|
||||
-- Started on 2019-02-20 21:09:05
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 198 (class 1255 OID 16458)
|
||||
-- Name: create_game(character varying); Type: PROCEDURE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE PROCEDURE public.create_game(INOUT new_host_connection_id character varying)
|
||||
LANGUAGE sql
|
||||
AS $$
|
||||
WITH new_game_id_holder (new_game_id) AS (
|
||||
SELECT n.random_number
|
||||
FROM (
|
||||
SELECT LPAD(FLOOR(random() * 10000)::varchar, 4, '0') AS random_number
|
||||
FROM generate_series(1, (SELECT COUNT(*) FROM public.games) + 10)
|
||||
) AS n
|
||||
LEFT OUTER JOIN
|
||||
public.games AS g on g.game_id = n.random_number
|
||||
WHERE g.id IS NULL
|
||||
LIMIT 1
|
||||
)
|
||||
INSERT INTO public.games (
|
||||
game_id,
|
||||
host_connection_id
|
||||
)
|
||||
VALUES (
|
||||
(SELECT new_game_id FROM new_game_id_holder),
|
||||
new_host_connection_id
|
||||
)
|
||||
RETURNING game_id;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER PROCEDURE public.create_game(INOUT new_host_connection_id character varying) OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- TOC entry 196 (class 1259 OID 16449)
|
||||
-- Name: games; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.games (
|
||||
id bigint NOT NULL,
|
||||
game_id character varying(4) NOT NULL,
|
||||
host_connection_id character varying(50) NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.games OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 197 (class 1259 OID 16453)
|
||||
-- Name: games_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.games_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.games_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 2816 (class 0 OID 0)
|
||||
-- Dependencies: 197
|
||||
-- Name: games_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.games_id_seq OWNED BY public.games.id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2687 (class 2604 OID 16455)
|
||||
-- Name: games id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games ALTER COLUMN id SET DEFAULT nextval('public.games_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 2689 (class 2606 OID 16457)
|
||||
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games
|
||||
ADD CONSTRAINT games_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
-- Completed on 2019-02-20 21:09:05
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,396 @@
|
||||
-- Downloaded from: https://github.com/Vinicius02612/sistema_da_associacao/blob/119156f1a695cb012e6c9c5806ef1266adb48036/Backend/Arq_bd/BASE_DIR.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.4
|
||||
-- Dumped by pg_dump version 16.4
|
||||
|
||||
-- Started on 2024-11-10 23:49:46
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 16444)
|
||||
-- Name: administrador; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.administrador (
|
||||
id integer NOT NULL,
|
||||
nome character(30) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.administrador OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 16474)
|
||||
-- Name: despesa; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.despesa (
|
||||
id integer NOT NULL,
|
||||
data date NOT NULL,
|
||||
valor double precision NOT NULL,
|
||||
origem character varying(100)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.despesa OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 16464)
|
||||
-- Name: mensalidade; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.mensalidade (
|
||||
id integer NOT NULL,
|
||||
titulo character varying(100),
|
||||
datavalidade date,
|
||||
datareferencia date,
|
||||
valor double precision NOT NULL,
|
||||
status boolean NOT NULL,
|
||||
socio_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.mensalidade OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 16459)
|
||||
-- Name: projeto; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.projeto (
|
||||
id integer NOT NULL,
|
||||
titulo character varying(100) NOT NULL,
|
||||
datainicio date NOT NULL,
|
||||
datafim date,
|
||||
status character varying(50),
|
||||
nomeorganizacao character varying(100)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.projeto OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 16479)
|
||||
-- Name: receita; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.receita (
|
||||
id integer NOT NULL,
|
||||
data date NOT NULL,
|
||||
valor double precision NOT NULL,
|
||||
origem character varying(100)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.receita OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 16484)
|
||||
-- Name: relatorio; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.relatorio (
|
||||
id integer NOT NULL,
|
||||
titulo character varying(100) NOT NULL,
|
||||
datacriacao date,
|
||||
receita_id integer,
|
||||
despesa_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.relatorio OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 216 (class 1259 OID 16434)
|
||||
-- Name: socio; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.socio (
|
||||
id integer NOT NULL,
|
||||
statuspagamento boolean,
|
||||
cargo character varying(100)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.socio OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 16454)
|
||||
-- Name: solicitacao; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.solicitacao (
|
||||
id integer NOT NULL,
|
||||
status boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.solicitacao OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 215 (class 1259 OID 16427)
|
||||
-- Name: usuario; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.usuario (
|
||||
id integer NOT NULL,
|
||||
nome character varying(100) NOT NULL,
|
||||
cpf character varying(14) NOT NULL,
|
||||
email character varying(100) NOT NULL,
|
||||
senha character varying(100) NOT NULL,
|
||||
tipousuario character varying(50) NOT NULL,
|
||||
datanascimento date,
|
||||
quantidadepessoasfamilia integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.usuario OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 4835 (class 0 OID 16444)
|
||||
-- Dependencies: 217
|
||||
-- Data for Name: administrador; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.administrador (id, nome) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4839 (class 0 OID 16474)
|
||||
-- Dependencies: 221
|
||||
-- Data for Name: despesa; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.despesa (id, data, valor, origem) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4838 (class 0 OID 16464)
|
||||
-- Dependencies: 220
|
||||
-- Data for Name: mensalidade; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.mensalidade (id, titulo, datavalidade, datareferencia, valor, status, socio_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4837 (class 0 OID 16459)
|
||||
-- Dependencies: 219
|
||||
-- Data for Name: projeto; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.projeto (id, titulo, datainicio, datafim, status, nomeorganizacao) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4840 (class 0 OID 16479)
|
||||
-- Dependencies: 222
|
||||
-- Data for Name: receita; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.receita (id, data, valor, origem) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4841 (class 0 OID 16484)
|
||||
-- Dependencies: 223
|
||||
-- Data for Name: relatorio; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.relatorio (id, titulo, datacriacao, receita_id, despesa_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4834 (class 0 OID 16434)
|
||||
-- Dependencies: 216
|
||||
-- Data for Name: socio; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.socio (id, statuspagamento, cargo) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4836 (class 0 OID 16454)
|
||||
-- Dependencies: 218
|
||||
-- Data for Name: solicitacao; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.solicitacao (id, status) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4833 (class 0 OID 16427)
|
||||
-- Dependencies: 215
|
||||
-- Data for Name: usuario; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.usuario (id, nome, cpf, email, senha, tipousuario, datanascimento, quantidadepessoasfamilia) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4672 (class 2606 OID 16448)
|
||||
-- Name: administrador administrador_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.administrador
|
||||
ADD CONSTRAINT administrador_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4680 (class 2606 OID 16478)
|
||||
-- Name: despesa despesa_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.despesa
|
||||
ADD CONSTRAINT despesa_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4678 (class 2606 OID 16468)
|
||||
-- Name: mensalidade mensalidade_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.mensalidade
|
||||
ADD CONSTRAINT mensalidade_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4676 (class 2606 OID 16463)
|
||||
-- Name: projeto projeto_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.projeto
|
||||
ADD CONSTRAINT projeto_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4682 (class 2606 OID 16483)
|
||||
-- Name: receita receita_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.receita
|
||||
ADD CONSTRAINT receita_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4684 (class 2606 OID 16488)
|
||||
-- Name: relatorio relatorio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.relatorio
|
||||
ADD CONSTRAINT relatorio_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4670 (class 2606 OID 16438)
|
||||
-- Name: socio socio_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.socio
|
||||
ADD CONSTRAINT socio_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4674 (class 2606 OID 16458)
|
||||
-- Name: solicitacao solicitacao_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.solicitacao
|
||||
ADD CONSTRAINT solicitacao_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4666 (class 2606 OID 16433)
|
||||
-- Name: usuario usuario_cpf_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.usuario
|
||||
ADD CONSTRAINT usuario_cpf_key UNIQUE (cpf);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4668 (class 2606 OID 16431)
|
||||
-- Name: usuario usuario_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.usuario
|
||||
ADD CONSTRAINT usuario_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4686 (class 2606 OID 16449)
|
||||
-- Name: administrador administrador_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.administrador
|
||||
ADD CONSTRAINT administrador_id_fkey FOREIGN KEY (id) REFERENCES public.usuario(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4687 (class 2606 OID 16469)
|
||||
-- Name: mensalidade mensalidade_socio_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.mensalidade
|
||||
ADD CONSTRAINT mensalidade_socio_id_fkey FOREIGN KEY (socio_id) REFERENCES public.socio(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4688 (class 2606 OID 16494)
|
||||
-- Name: relatorio relatorio_despesa_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.relatorio
|
||||
ADD CONSTRAINT relatorio_despesa_id_fkey FOREIGN KEY (despesa_id) REFERENCES public.despesa(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4689 (class 2606 OID 16489)
|
||||
-- Name: relatorio relatorio_receita_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.relatorio
|
||||
ADD CONSTRAINT relatorio_receita_id_fkey FOREIGN KEY (receita_id) REFERENCES public.receita(id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4685 (class 2606 OID 16439)
|
||||
-- Name: socio socio_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.socio
|
||||
ADD CONSTRAINT socio_id_fkey FOREIGN KEY (id) REFERENCES public.usuario(id);
|
||||
|
||||
|
||||
-- Completed on 2024-11-10 23:49:46
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,940 @@
|
||||
-- Downloaded from: https://github.com/WhoIsKatie/e-Hotels/blob/83bbd189f6f8ee312e8fca8830e33ae67b18558b/server/database.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 15.2
|
||||
-- Dumped by pg_dump version 15.2
|
||||
|
||||
-- Started on 2023-03-31 21:08:48
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 3475 (class 1262 OID 16899)
|
||||
-- Name: e-Hotels; Type: DATABASE; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DATABASE "e-Hotels" WITH TEMPLATE = template0 ENCODING = 'UTF8' LOCALE_PROVIDER = libc LOCALE = 'English_United States.1252';
|
||||
|
||||
|
||||
ALTER DATABASE "e-Hotels" OWNER TO postgres;
|
||||
|
||||
\connect -reuse-previous=on "dbname='e-Hotels'"
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 238 (class 1255 OID 17123)
|
||||
-- Name: employee_is_manager(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.employee_is_manager() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$BEGIN
|
||||
IF NOT EXISTS (select * FROM inst_role WHERE (role_sin = NEW.manager_id
|
||||
AND role_name = 'manager'))
|
||||
THEN ROLLBACK;
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END;$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.employee_is_manager() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 239 (class 1255 OID 17350)
|
||||
-- Name: employee_not_customer_or_same_hotel(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.employee_not_customer_or_same_hotel() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$BEGIN
|
||||
IF EXISTS (SELECT * FROM booking WHERE (booking_id = NEW.booking_id
|
||||
AND customer_sin = NEW.employee_sin))
|
||||
THEN ROLLBACK;
|
||||
ELSE
|
||||
IF NOT EXISTS (SELECT * FROM booking AS b, employee AS e
|
||||
WHERE (b.booking_id = NEW.booking_id
|
||||
AND b.hotel_id = e.hotel_id))
|
||||
THEN ROLLBACK;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END;$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.employee_not_customer_or_same_hotel() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1259 OID 16925)
|
||||
-- Name: chain_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.chain_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.chain_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 235 (class 1259 OID 17127)
|
||||
-- Name: hotel_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.hotel_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.hotel_id_seq OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1259 OID 16918)
|
||||
-- Name: hotel; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.hotel (
|
||||
hotel_id integer DEFAULT nextval('public.hotel_id_seq'::regclass) NOT NULL,
|
||||
chain_id integer NOT NULL,
|
||||
street_num integer NOT NULL,
|
||||
street_name character varying(100) NOT NULL,
|
||||
unit_num integer,
|
||||
city character varying(100) NOT NULL,
|
||||
state character varying(2) NOT NULL,
|
||||
country character varying(30) NOT NULL,
|
||||
postal_code character varying(10) NOT NULL,
|
||||
rating integer NOT NULL,
|
||||
manager_id numeric(9,0) NOT NULL,
|
||||
email character varying(100) NOT NULL,
|
||||
CONSTRAINT hotel_rating_check CHECK (((rating >= 1) AND (rating <= 5)))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.hotel OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1259 OID 16922)
|
||||
-- Name: hotel_chain; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.hotel_chain (
|
||||
chain_id integer DEFAULT nextval('public.chain_id_seq'::regclass) NOT NULL,
|
||||
name character varying(50) NOT NULL,
|
||||
street_num integer NOT NULL,
|
||||
street_name character varying(100) NOT NULL,
|
||||
unit_num integer,
|
||||
city character varying(20) NOT NULL,
|
||||
state character(2),
|
||||
country character varying(30),
|
||||
postal_code character varying(10)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.hotel_chain OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 233 (class 1259 OID 16959)
|
||||
-- Name: room; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.room (
|
||||
room_number integer NOT NULL,
|
||||
price money,
|
||||
capacity integer,
|
||||
max_capacity integer,
|
||||
hotel_id integer NOT NULL,
|
||||
CONSTRAINT room_check CHECK (((capacity >= 1) AND (max_capacity >= capacity))),
|
||||
CONSTRAINT room_number_check CHECK ((room_number >= 0))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.room OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 237 (class 1259 OID 17371)
|
||||
-- Name: available_rooms; Type: VIEW; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE VIEW public.available_rooms AS
|
||||
SELECT room.room_number,
|
||||
room.price,
|
||||
room.capacity,
|
||||
room.max_capacity,
|
||||
hotel.hotel_id,
|
||||
hotel.city,
|
||||
hotel.state,
|
||||
hotel.country,
|
||||
hotel.rating,
|
||||
hotel_chain.name AS chain_name
|
||||
FROM ((public.room
|
||||
JOIN public.hotel ON ((room.hotel_id = hotel.hotel_id)))
|
||||
JOIN public.hotel_chain ON ((hotel.chain_id = hotel_chain.chain_id)));
|
||||
|
||||
|
||||
ALTER TABLE public.available_rooms OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 214 (class 1259 OID 16900)
|
||||
-- Name: booking; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.booking (
|
||||
booking_id bigint NOT NULL,
|
||||
checkin_date date NOT NULL,
|
||||
checkout_date date NOT NULL,
|
||||
hotel_id integer NOT NULL,
|
||||
customer_sin numeric(9,0) NOT NULL,
|
||||
room_number integer NOT NULL,
|
||||
CONSTRAINT valid_dates CHECK ((checkout_date > checkin_date))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.booking OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 215 (class 1259 OID 16903)
|
||||
-- Name: booking_booking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.booking_booking_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.booking_booking_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 3476 (class 0 OID 0)
|
||||
-- Dependencies: 215
|
||||
-- Name: booking_booking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.booking_booking_id_seq OWNED BY public.booking.booking_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 16910)
|
||||
-- Name: chain_inst_phone_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.chain_inst_phone_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.chain_inst_phone_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 230 (class 1259 OID 16952)
|
||||
-- Name: customer; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.customer (
|
||||
customer_sin numeric(9,0) NOT NULL,
|
||||
registration_date date NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.customer OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 16914)
|
||||
-- Name: employee; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.employee (
|
||||
sin numeric(9,0) NOT NULL,
|
||||
hotel_id integer NOT NULL,
|
||||
salary money NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.employee OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 236 (class 1259 OID 17366)
|
||||
-- Name: hotel_capacity; Type: VIEW; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE VIEW public.hotel_capacity AS
|
||||
SELECT room.capacity,
|
||||
room.max_capacity,
|
||||
hotel.hotel_id
|
||||
FROM (public.room
|
||||
JOIN public.hotel ON ((room.hotel_id = hotel.hotel_id)));
|
||||
|
||||
|
||||
ALTER TABLE public.hotel_capacity OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1259 OID 16929)
|
||||
-- Name: inst_amenity; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_amenity (
|
||||
amenity_id integer NOT NULL,
|
||||
amenity character varying(100) NOT NULL,
|
||||
hotel_id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_amenity OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 216 (class 1259 OID 16907)
|
||||
-- Name: inst_chain_phone; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_chain_phone (
|
||||
chain_phone_id integer DEFAULT nextval('public.chain_inst_phone_id_seq'::regclass) NOT NULL,
|
||||
phone_number numeric(10,0) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_chain_phone OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1259 OID 16932)
|
||||
-- Name: inst_concern; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_concern (
|
||||
concern_id integer NOT NULL,
|
||||
concern character varying(200) NOT NULL,
|
||||
hotel_id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_concern OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1259 OID 16938)
|
||||
-- Name: inst_email_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.inst_email_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.inst_email_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1259 OID 16935)
|
||||
-- Name: inst_email; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_email (
|
||||
email_id integer DEFAULT nextval('public.inst_email_id_seq'::regclass) NOT NULL,
|
||||
email character varying(100) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_email OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1259 OID 16926)
|
||||
-- Name: inst_hotel_phone; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_hotel_phone (
|
||||
phone_id integer NOT NULL,
|
||||
phone_number numeric(10,0) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_hotel_phone OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 227 (class 1259 OID 16939)
|
||||
-- Name: inst_role; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.inst_role (
|
||||
role_sin numeric(9,0) NOT NULL,
|
||||
role_name character varying(80) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.inst_role OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 228 (class 1259 OID 16942)
|
||||
-- Name: manages; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.manages (
|
||||
booking_id bigint NOT NULL,
|
||||
employee_sin numeric(9,0) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.manages OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 229 (class 1259 OID 16945)
|
||||
-- Name: person; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.person (
|
||||
sin numeric(9,0) NOT NULL,
|
||||
first_name character varying,
|
||||
last_name character varying,
|
||||
middle_name character varying,
|
||||
street_num integer,
|
||||
street_name character varying,
|
||||
unit_num integer,
|
||||
city character varying,
|
||||
state character varying(2),
|
||||
country character varying(20),
|
||||
postal_code character varying(10),
|
||||
CONSTRAINT person_street_num_check CHECK ((street_num > 0))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.person OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 231 (class 1259 OID 16955)
|
||||
-- Name: renting; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.renting (
|
||||
booking_id bigint NOT NULL,
|
||||
cc_number numeric(16,0) NOT NULL,
|
||||
expiry_date date NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.renting OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 232 (class 1259 OID 16958)
|
||||
-- Name: renting_booking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.renting_booking_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.renting_booking_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 3477 (class 0 OID 0)
|
||||
-- Dependencies: 232
|
||||
-- Name: renting_booking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.renting_booking_id_seq OWNED BY public.renting.booking_id;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 234 (class 1259 OID 16964)
|
||||
-- Name: supervises; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.supervises (
|
||||
subordinate_sin numeric(9,0) NOT NULL,
|
||||
supervisor_sin numeric(9,0) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.supervises OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 3248 (class 2604 OID 16967)
|
||||
-- Name: booking booking_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.booking ALTER COLUMN booking_id SET DEFAULT nextval('public.booking_booking_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3253 (class 2604 OID 16971)
|
||||
-- Name: renting booking_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.renting ALTER COLUMN booking_id SET DEFAULT nextval('public.renting_booking_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3263 (class 2606 OID 16973)
|
||||
-- Name: booking booking_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.booking
|
||||
ADD CONSTRAINT booking_pkey PRIMARY KEY (booking_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3266 (class 2606 OID 16977)
|
||||
-- Name: inst_chain_phone chain_inst_phone_number_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_chain_phone
|
||||
ADD CONSTRAINT chain_inst_phone_number_key UNIQUE (phone_number);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3268 (class 2606 OID 16979)
|
||||
-- Name: inst_chain_phone chain_inst_phone_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_chain_phone
|
||||
ADD CONSTRAINT chain_inst_phone_pkey PRIMARY KEY (chain_phone_id, phone_number);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3298 (class 2606 OID 17356)
|
||||
-- Name: customer customer_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.customer
|
||||
ADD CONSTRAINT customer_pkey PRIMARY KEY (customer_sin);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3270 (class 2606 OID 16983)
|
||||
-- Name: employee employee_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employee
|
||||
ADD CONSTRAINT employee_pkey PRIMARY KEY (sin);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3280 (class 2606 OID 16985)
|
||||
-- Name: hotel_chain hotel_chain_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.hotel_chain
|
||||
ADD CONSTRAINT hotel_chain_pkey PRIMARY KEY (chain_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3282 (class 2606 OID 16987)
|
||||
-- Name: inst_hotel_phone hotel_inst_phone_number_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_hotel_phone
|
||||
ADD CONSTRAINT hotel_inst_phone_number_key UNIQUE (phone_number);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3275 (class 2606 OID 17121)
|
||||
-- Name: hotel hotel_manager_unique; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.hotel
|
||||
ADD CONSTRAINT hotel_manager_unique UNIQUE (manager_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3277 (class 2606 OID 17201)
|
||||
-- Name: hotel hotel_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.hotel
|
||||
ADD CONSTRAINT hotel_pkey PRIMARY KEY (hotel_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3284 (class 2606 OID 16991)
|
||||
-- Name: inst_amenity inst_amenity_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_amenity
|
||||
ADD CONSTRAINT inst_amenity_pkey PRIMARY KEY (amenity_id, amenity);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3286 (class 2606 OID 17132)
|
||||
-- Name: inst_concern inst_concern_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_concern
|
||||
ADD CONSTRAINT inst_concern_pkey PRIMARY KEY (concern_id, concern);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3288 (class 2606 OID 16995)
|
||||
-- Name: inst_email inst_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_email
|
||||
ADD CONSTRAINT inst_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3290 (class 2606 OID 16997)
|
||||
-- Name: inst_email inst_email_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_email
|
||||
ADD CONSTRAINT inst_email_pkey PRIMARY KEY (email_id, email);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3292 (class 2606 OID 17130)
|
||||
-- Name: inst_role inst_role_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_role
|
||||
ADD CONSTRAINT inst_role_pkey PRIMARY KEY (role_sin, role_name);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3294 (class 2606 OID 17307)
|
||||
-- Name: manages manages_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.manages
|
||||
ADD CONSTRAINT manages_pkey PRIMARY KEY (booking_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3296 (class 2606 OID 17003)
|
||||
-- Name: person person_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.person
|
||||
ADD CONSTRAINT person_pkey PRIMARY KEY (sin);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3300 (class 2606 OID 17309)
|
||||
-- Name: renting renting_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.renting
|
||||
ADD CONSTRAINT renting_pkey PRIMARY KEY (booking_id, cc_number, expiry_date);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3303 (class 2606 OID 17242)
|
||||
-- Name: room room_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.room
|
||||
ADD CONSTRAINT room_pkey PRIMARY KEY (room_number, hotel_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3259 (class 1259 OID 17346)
|
||||
-- Name: booking_checkin_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX booking_checkin_index ON public.booking USING btree (checkin_date);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3260 (class 1259 OID 17347)
|
||||
-- Name: booking_checkout_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX booking_checkout_index ON public.booking USING btree (checkout_date);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3261 (class 1259 OID 17345)
|
||||
-- Name: booking_customer_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX booking_customer_index ON public.booking USING btree (customer_sin);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3264 (class 1259 OID 17348)
|
||||
-- Name: booking_room_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX booking_room_index ON public.booking USING btree (room_number);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3271 (class 1259 OID 17294)
|
||||
-- Name: hotel_chain_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX hotel_chain_index ON public.hotel USING btree (chain_id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3272 (class 1259 OID 17295)
|
||||
-- Name: hotel_city_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX hotel_city_index ON public.hotel USING btree (city);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3273 (class 1259 OID 17296)
|
||||
-- Name: hotel_country_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX hotel_country_index ON public.hotel USING btree (country);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3278 (class 1259 OID 17297)
|
||||
-- Name: hotel_rating_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX hotel_rating_index ON public.hotel USING btree (rating);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3301 (class 1259 OID 17293)
|
||||
-- Name: room_capacity_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX room_capacity_index ON public.room USING btree (max_capacity);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3304 (class 1259 OID 17298)
|
||||
-- Name: room_price_index; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX room_price_index ON public.room USING btree (price);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3324 (class 2620 OID 17134)
|
||||
-- Name: hotel hotel_manager_constraint_trigger; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE CONSTRAINT TRIGGER hotel_manager_constraint_trigger AFTER INSERT OR UPDATE ON public.hotel DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION public.employee_is_manager();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3325 (class 2620 OID 17353)
|
||||
-- Name: manages managing_employee_constraint_trigger; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE CONSTRAINT TRIGGER managing_employee_constraint_trigger AFTER INSERT OR UPDATE ON public.manages NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE FUNCTION public.employee_not_customer_or_same_hotel();
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3305 (class 2606 OID 17357)
|
||||
-- Name: booking booking_customer_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.booking
|
||||
ADD CONSTRAINT booking_customer_sin_fkey FOREIGN KEY (customer_sin) REFERENCES public.customer(customer_sin);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3306 (class 2606 OID 17325)
|
||||
-- Name: booking booking_hotel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.booking
|
||||
ADD CONSTRAINT booking_hotel_id_fkey FOREIGN KEY (hotel_id) REFERENCES public.hotel(hotel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3307 (class 2606 OID 17340)
|
||||
-- Name: booking booking_hotel_id_room_number_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.booking
|
||||
ADD CONSTRAINT booking_hotel_id_room_number_fkey FOREIGN KEY (hotel_id, room_number) REFERENCES public.room(hotel_id, room_number) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3308 (class 2606 OID 17030)
|
||||
-- Name: inst_chain_phone chain_inst_phone_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_chain_phone
|
||||
ADD CONSTRAINT chain_inst_phone_id_fkey FOREIGN KEY (chain_phone_id) REFERENCES public.hotel_chain(chain_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3319 (class 2606 OID 17310)
|
||||
-- Name: customer customer_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.customer
|
||||
ADD CONSTRAINT customer_sin_fkey FOREIGN KEY (customer_sin) REFERENCES public.person(sin) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3309 (class 2606 OID 17258)
|
||||
-- Name: employee employee_hotel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employee
|
||||
ADD CONSTRAINT employee_hotel_id_fkey FOREIGN KEY (hotel_id) REFERENCES public.hotel(hotel_id) DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3310 (class 2606 OID 17045)
|
||||
-- Name: employee employee_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employee
|
||||
ADD CONSTRAINT employee_sin_fkey FOREIGN KEY (sin) REFERENCES public.person(sin) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3311 (class 2606 OID 17050)
|
||||
-- Name: hotel hotel_chain_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.hotel
|
||||
ADD CONSTRAINT hotel_chain_id_fkey FOREIGN KEY (chain_id) REFERENCES public.hotel_chain(chain_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3313 (class 2606 OID 17273)
|
||||
-- Name: inst_hotel_phone hotel_inst_phone_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_hotel_phone
|
||||
ADD CONSTRAINT hotel_inst_phone_id_fkey FOREIGN KEY (phone_id) REFERENCES public.hotel(hotel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3314 (class 2606 OID 17263)
|
||||
-- Name: inst_amenity inst_amenity_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_amenity
|
||||
ADD CONSTRAINT inst_amenity_id_fkey FOREIGN KEY (amenity_id, hotel_id) REFERENCES public.room(room_number, hotel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3315 (class 2606 OID 17268)
|
||||
-- Name: inst_concern inst_concern_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_concern
|
||||
ADD CONSTRAINT inst_concern_id_fkey FOREIGN KEY (concern_id, hotel_id) REFERENCES public.room(room_number, hotel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3316 (class 2606 OID 17070)
|
||||
-- Name: inst_email inst_email_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_email
|
||||
ADD CONSTRAINT inst_email_id_fkey FOREIGN KEY (email_id) REFERENCES public.hotel_chain(chain_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3317 (class 2606 OID 17075)
|
||||
-- Name: inst_role inst_role_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.inst_role
|
||||
ADD CONSTRAINT inst_role_sin_fkey FOREIGN KEY (role_sin) REFERENCES public.employee(sin) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3312 (class 2606 OID 17080)
|
||||
-- Name: hotel manager_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.hotel
|
||||
ADD CONSTRAINT manager_id_fkey FOREIGN KEY (manager_id) REFERENCES public.employee(sin) ON UPDATE CASCADE ON DELETE RESTRICT DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3318 (class 2606 OID 17090)
|
||||
-- Name: manages manages_employee_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.manages
|
||||
ADD CONSTRAINT manages_employee_sin_fkey FOREIGN KEY (employee_sin) REFERENCES public.employee(sin) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3320 (class 2606 OID 17105)
|
||||
-- Name: renting renting_booking_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.renting
|
||||
ADD CONSTRAINT renting_booking_id_fkey FOREIGN KEY (booking_id) REFERENCES public.booking(booking_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3321 (class 2606 OID 17288)
|
||||
-- Name: room room_hotel_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.room
|
||||
ADD CONSTRAINT room_hotel_id_fkey FOREIGN KEY (hotel_id) REFERENCES public.hotel(hotel_id) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3322 (class 2606 OID 17110)
|
||||
-- Name: supervises supervises_subordinate_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.supervises
|
||||
ADD CONSTRAINT supervises_subordinate_sin_fkey FOREIGN KEY (subordinate_sin) REFERENCES public.employee(sin) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 3323 (class 2606 OID 17115)
|
||||
-- Name: supervises supervises_supervisor_sin_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.supervises
|
||||
ADD CONSTRAINT supervises_supervisor_sin_fkey FOREIGN KEY (supervisor_sin) REFERENCES public.employee(sin) ON UPDATE CASCADE ON DELETE CASCADE;
|
||||
|
||||
|
||||
-- Completed on 2023-03-31 21:08:49
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,419 @@
|
||||
-- Downloaded from: https://github.com/Xarpunk/DemExam/blob/3a08536412872ed8495b1d529cadbd1dc1bb004a/dem_backup.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 17.4
|
||||
-- Dumped by pg_dump version 17.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: update_timestamp(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.update_timestamp() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.update_timestamp() OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: material_receipts; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.material_receipts (
|
||||
receipt_id integer NOT NULL,
|
||||
material_id integer NOT NULL,
|
||||
quantity numeric(10,2) NOT NULL,
|
||||
receipt_date date NOT NULL,
|
||||
unit_price numeric(10,2) NOT NULL,
|
||||
supplier_id integer NOT NULL,
|
||||
invoice_number character varying(50),
|
||||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.material_receipts OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: material_receipts_receipt_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.material_receipts_receipt_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.material_receipts_receipt_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: material_receipts_receipt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.material_receipts_receipt_id_seq OWNED BY public.material_receipts.receipt_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_usage; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.material_usage (
|
||||
usage_id integer NOT NULL,
|
||||
material_id integer NOT NULL,
|
||||
quantity numeric(10,2) NOT NULL,
|
||||
usage_date date NOT NULL,
|
||||
production_id integer,
|
||||
notes text,
|
||||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.material_usage OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: material_usage_usage_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.material_usage_usage_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.material_usage_usage_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: material_usage_usage_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.material_usage_usage_id_seq OWNED BY public.material_usage.usage_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.materials (
|
||||
material_id integer NOT NULL,
|
||||
material_name character varying(100) NOT NULL,
|
||||
description text,
|
||||
unit_of_measure character varying(20) NOT NULL,
|
||||
current_quantity numeric(10,2) DEFAULT 0 NOT NULL,
|
||||
min_quantity numeric(10,2) DEFAULT 0 NOT NULL,
|
||||
supplier_id integer,
|
||||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.materials OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: materials_material_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.materials_material_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.materials_material_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: materials_material_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.materials_material_id_seq OWNED BY public.materials.material_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: suppliers; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.suppliers (
|
||||
supplier_id integer NOT NULL,
|
||||
supplier_name character varying(100) NOT NULL,
|
||||
contact_person character varying(100),
|
||||
phone character varying(20),
|
||||
email character varying(100),
|
||||
address text,
|
||||
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.suppliers OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: suppliers_supplier_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.suppliers_supplier_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.suppliers_supplier_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: suppliers_supplier_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.suppliers_supplier_id_seq OWNED BY public.suppliers.supplier_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_receipts receipt_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_receipts ALTER COLUMN receipt_id SET DEFAULT nextval('public.material_receipts_receipt_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_usage usage_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_usage ALTER COLUMN usage_id SET DEFAULT nextval('public.material_usage_usage_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials material_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.materials ALTER COLUMN material_id SET DEFAULT nextval('public.materials_material_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: suppliers supplier_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.suppliers ALTER COLUMN supplier_id SET DEFAULT nextval('public.suppliers_supplier_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: material_receipts; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.material_receipts (receipt_id, material_id, quantity, receipt_date, unit_price, supplier_id, invoice_number, created_at) FROM stdin;
|
||||
2 2 500.00 2023-05-12 320.75 1 INV-2023-002 2025-06-17 00:00:00+03
|
||||
3 3 300.00 2023-05-15 180.00 2 INV-2023-003 2025-06-17 00:00:00+03
|
||||
4 4 50.00 2023-05-18 1200.00 3 INV-2023-004 2025-06-17 00:00:00+03
|
||||
5 5 30.00 2023-05-20 450.00 2 INV-2023-005 2025-06-17 00:00:00+03
|
||||
11 11 100.00 2025-06-16 500.00 1 \N 2025-06-17 00:00:00+03
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: material_usage; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.material_usage (usage_id, material_id, quantity, usage_date, production_id, notes, created_at) FROM stdin;
|
||||
2 2 120.50 2023-05-13 1002 Izgotovlenie detaley 2025-06-17 00:00:00+03
|
||||
3 3 75.25 2023-05-16 1003 Litye komponentov 2025-06-17 00:00:00+03
|
||||
4 4 10.00 2023-05-19 1004 Sborka upakovki 2025-06-17 00:00:00+03
|
||||
5 5 5.00 2023-05-21 1005 Pokraska izdeliy 2025-06-17 00:00:00+03
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: materials; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.materials (material_id, material_name, description, unit_of_measure, current_quantity, min_quantity, supplier_id, created_at, updated_at) FROM stdin;
|
||||
2 Stal nerzhaveyushaya Listy 3mm, marka 304 kg 1200.50 300.00 1 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
3 Polipropilen Granuly dlya litya kg 750.25 200.00 2 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
4 Fanera Fanera 10mm, sort A list 80.00 20.00 3 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
5 Kraska belaya Akrilovaya, matovaya sht 45.00 10.00 2 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
11 Block \N sht 100.00 0.00 1 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: suppliers; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.suppliers (supplier_id, supplier_name, contact_person, phone, email, address, created_at, updated_at) FROM stdin;
|
||||
1 OOO "MetallSnab" Ivanov Petr +79161234567 metal@example.com g. Moskva, ul. Metallurgov, 15 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
2 AO "HimProm" Sidorova Anna +79167654321 chem@example.com g. Sankt-Peterburg, pr. Himikov, 42 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
3 IP "Derevoobrabotka" Petrov Vasiliy +79031234567 wood@example.com g. Ekaterinburg, ul. Lesnaya, 7 2025-06-17 00:00:00+03 2025-06-17 00:00:00+03
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_receipts_receipt_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.material_receipts_receipt_id_seq', 12, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_usage_usage_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.material_usage_usage_id_seq', 5, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials_material_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.materials_material_id_seq', 42, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: suppliers_supplier_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.suppliers_supplier_id_seq', 3, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_receipts material_receipts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_receipts
|
||||
ADD CONSTRAINT material_receipts_pkey PRIMARY KEY (receipt_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_usage material_usage_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_usage
|
||||
ADD CONSTRAINT material_usage_pkey PRIMARY KEY (usage_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials materials_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.materials
|
||||
ADD CONSTRAINT materials_pkey PRIMARY KEY (material_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: suppliers suppliers_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.suppliers
|
||||
ADD CONSTRAINT suppliers_pkey PRIMARY KEY (supplier_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_materials_supplier; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_materials_supplier ON public.materials USING btree (supplier_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_receipts_material; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_receipts_material ON public.material_receipts USING btree (material_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_receipts_supplier; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_receipts_supplier ON public.material_receipts USING btree (supplier_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_usage_material; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_usage_material ON public.material_usage USING btree (material_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials update_materials_timestamp; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER update_materials_timestamp BEFORE UPDATE ON public.materials FOR EACH ROW EXECUTE FUNCTION public.update_timestamp();
|
||||
|
||||
ALTER TABLE public.materials DISABLE TRIGGER update_materials_timestamp;
|
||||
|
||||
|
||||
--
|
||||
-- Name: suppliers update_suppliers_timestamp; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER update_suppliers_timestamp BEFORE UPDATE ON public.suppliers FOR EACH ROW EXECUTE FUNCTION public.update_timestamp();
|
||||
|
||||
ALTER TABLE public.suppliers DISABLE TRIGGER update_suppliers_timestamp;
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_receipts material_receipts_material_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_receipts
|
||||
ADD CONSTRAINT material_receipts_material_id_fkey FOREIGN KEY (material_id) REFERENCES public.materials(material_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_receipts material_receipts_supplier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_receipts
|
||||
ADD CONSTRAINT material_receipts_supplier_id_fkey FOREIGN KEY (supplier_id) REFERENCES public.suppliers(supplier_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: material_usage material_usage_material_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.material_usage
|
||||
ADD CONSTRAINT material_usage_material_id_fkey FOREIGN KEY (material_id) REFERENCES public.materials(material_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: materials materials_supplier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.materials
|
||||
ADD CONSTRAINT materials_supplier_id_fkey FOREIGN KEY (supplier_id) REFERENCES public.suppliers(supplier_id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,526 @@
|
||||
-- Downloaded from: https://github.com/Yesk0/KBTU_Database_24-25/blob/ad089a5cc4f6302d82136d7722a929548a3c0e76/Employee.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.4
|
||||
-- Dumped by pg_dump version 16.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
COMMENT ON SCHEMA public IS 'Standard public schema';
|
||||
|
||||
|
||||
--
|
||||
-- Name: adminpack; Type: EXTENSION; Schema: -; Owner: -
|
||||
--
|
||||
|
||||
CREATE EXTENSION IF NOT EXISTS adminpack WITH SCHEMA pg_catalog;
|
||||
|
||||
|
||||
--
|
||||
-- Name: EXTENSION adminpack; Type: COMMENT; Schema: -; Owner:
|
||||
--
|
||||
|
||||
COMMENT ON EXTENSION adminpack IS 'administrative functions for PostgreSQL';
|
||||
|
||||
|
||||
--
|
||||
-- Name: mpaa_rating; Type: TYPE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TYPE public.mpaa_rating AS ENUM (
|
||||
'G',
|
||||
'PG',
|
||||
'PG-13',
|
||||
'R',
|
||||
'NC-17'
|
||||
);
|
||||
|
||||
|
||||
ALTER TYPE public.mpaa_rating OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: year; Type: DOMAIN; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE DOMAIN public.year AS integer
|
||||
CONSTRAINT year_check CHECK (((VALUE >= 1901) AND (VALUE <= 2155)));
|
||||
|
||||
|
||||
ALTER DOMAIN public.year OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: _group_concat(text, text); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public._group_concat(text, text) RETURNS text
|
||||
LANGUAGE sql IMMUTABLE
|
||||
AS $_$
|
||||
SELECT CASE
|
||||
WHEN $2 IS NULL THEN $1
|
||||
WHEN $1 IS NULL THEN $2
|
||||
ELSE $1 || ', ' || $2
|
||||
END
|
||||
$_$;
|
||||
|
||||
|
||||
ALTER FUNCTION public._group_concat(text, text) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: film_in_stock(integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.film_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) RETURNS SETOF integer
|
||||
LANGUAGE sql
|
||||
AS $_$
|
||||
SELECT inventory_id
|
||||
FROM inventory
|
||||
WHERE film_id = $1
|
||||
AND store_id = $2
|
||||
AND inventory_in_stock(inventory_id);
|
||||
$_$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.film_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: film_not_in_stock(integer, integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.film_not_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) RETURNS SETOF integer
|
||||
LANGUAGE sql
|
||||
AS $_$
|
||||
SELECT inventory_id
|
||||
FROM inventory
|
||||
WHERE film_id = $1
|
||||
AND store_id = $2
|
||||
AND NOT inventory_in_stock(inventory_id);
|
||||
$_$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.film_not_in_stock(p_film_id integer, p_store_id integer, OUT p_film_count integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: get_customer_balance(integer, timestamp without time zone); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.get_customer_balance(p_customer_id integer, p_effective_date timestamp without time zone) RETURNS numeric
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
--#OK, WE NEED TO CALCULATE THE CURRENT BALANCE GIVEN A CUSTOMER_ID AND A DATE
|
||||
--#THAT WE WANT THE BALANCE TO BE EFFECTIVE FOR. THE BALANCE IS:
|
||||
--# 1) RENTAL FEES FOR ALL PREVIOUS RENTALS
|
||||
--# 2) ONE DOLLAR FOR EVERY DAY THE PREVIOUS RENTALS ARE OVERDUE
|
||||
--# 3) IF A FILM IS MORE THAN RENTAL_DURATION * 2 OVERDUE, CHARGE THE REPLACEMENT_COST
|
||||
--# 4) SUBTRACT ALL PAYMENTS MADE BEFORE THE DATE SPECIFIED
|
||||
DECLARE
|
||||
v_rentfees DECIMAL(5,2); --#FEES PAID TO RENT THE VIDEOS INITIALLY
|
||||
v_overfees INTEGER; --#LATE FEES FOR PRIOR RENTALS
|
||||
v_payments DECIMAL(5,2); --#SUM OF PAYMENTS MADE PREVIOUSLY
|
||||
BEGIN
|
||||
SELECT COALESCE(SUM(film.rental_rate),0) INTO v_rentfees
|
||||
FROM film, inventory, rental
|
||||
WHERE film.film_id = inventory.film_id
|
||||
AND inventory.inventory_id = rental.inventory_id
|
||||
AND rental.rental_date <= p_effective_date
|
||||
AND rental.customer_id = p_customer_id;
|
||||
|
||||
SELECT COALESCE(SUM(IF((rental.return_date - rental.rental_date) > (film.rental_duration * '1 day'::interval),
|
||||
((rental.return_date - rental.rental_date) - (film.rental_duration * '1 day'::interval)),0)),0) INTO v_overfees
|
||||
FROM rental, inventory, film
|
||||
WHERE film.film_id = inventory.film_id
|
||||
AND inventory.inventory_id = rental.inventory_id
|
||||
AND rental.rental_date <= p_effective_date
|
||||
AND rental.customer_id = p_customer_id;
|
||||
|
||||
SELECT COALESCE(SUM(payment.amount),0) INTO v_payments
|
||||
FROM payment
|
||||
WHERE payment.payment_date <= p_effective_date
|
||||
AND payment.customer_id = p_customer_id;
|
||||
|
||||
RETURN v_rentfees + v_overfees - v_payments;
|
||||
END
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.get_customer_balance(p_customer_id integer, p_effective_date timestamp without time zone) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: inventory_held_by_customer(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.inventory_held_by_customer(p_inventory_id integer) RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_customer_id INTEGER;
|
||||
BEGIN
|
||||
|
||||
SELECT customer_id INTO v_customer_id
|
||||
FROM rental
|
||||
WHERE return_date IS NULL
|
||||
AND inventory_id = p_inventory_id;
|
||||
|
||||
RETURN v_customer_id;
|
||||
END $$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.inventory_held_by_customer(p_inventory_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: inventory_in_stock(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.inventory_in_stock(p_inventory_id integer) RETURNS boolean
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_rentals INTEGER;
|
||||
v_out INTEGER;
|
||||
BEGIN
|
||||
-- AN ITEM IS IN-STOCK IF THERE ARE EITHER NO ROWS IN THE rental TABLE
|
||||
-- FOR THE ITEM OR ALL ROWS HAVE return_date POPULATED
|
||||
|
||||
SELECT count(*) INTO v_rentals
|
||||
FROM rental
|
||||
WHERE inventory_id = p_inventory_id;
|
||||
|
||||
IF v_rentals = 0 THEN
|
||||
RETURN TRUE;
|
||||
END IF;
|
||||
|
||||
SELECT COUNT(rental_id) INTO v_out
|
||||
FROM inventory LEFT JOIN rental USING(inventory_id)
|
||||
WHERE inventory.inventory_id = p_inventory_id
|
||||
AND rental.return_date IS NULL;
|
||||
|
||||
IF v_out > 0 THEN
|
||||
RETURN FALSE;
|
||||
ELSE
|
||||
RETURN TRUE;
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.inventory_in_stock(p_inventory_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: last_day(timestamp without time zone); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.last_day(timestamp without time zone) RETURNS date
|
||||
LANGUAGE sql IMMUTABLE STRICT
|
||||
AS $_$
|
||||
SELECT CASE
|
||||
WHEN EXTRACT(MONTH FROM $1) = 12 THEN
|
||||
(((EXTRACT(YEAR FROM $1) + 1) operator(pg_catalog.||) '-01-01')::date - INTERVAL '1 day')::date
|
||||
ELSE
|
||||
((EXTRACT(YEAR FROM $1) operator(pg_catalog.||) '-' operator(pg_catalog.||) (EXTRACT(MONTH FROM $1) + 1) operator(pg_catalog.||) '-01')::date - INTERVAL '1 day')::date
|
||||
END
|
||||
$_$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.last_day(timestamp without time zone) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: last_updated(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.last_updated() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.last_update = CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END $$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.last_updated() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: group_concat(text); Type: AGGREGATE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE AGGREGATE public.group_concat(text) (
|
||||
SFUNC = public._group_concat,
|
||||
STYPE = text
|
||||
);
|
||||
|
||||
|
||||
ALTER AGGREGATE public.group_concat(text) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: actor_actor_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.actor_actor_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.actor_actor_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: address_address_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.address_address_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.address_address_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: category_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.category_category_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.category_category_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: city_city_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.city_city_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.city_city_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: country_country_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.country_country_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.country_country_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: customer_customer_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.customer_customer_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.customer_customer_id_seq OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: employee; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.employee (
|
||||
eid character varying(100),
|
||||
name character varying(100),
|
||||
job_title character varying(100),
|
||||
department character varying(100),
|
||||
business_unit character varying(100),
|
||||
gender character varying(10),
|
||||
ethnicity character varying(100),
|
||||
age integer,
|
||||
annual_salary numeric(15,2),
|
||||
bonus_percentage numeric(15,2),
|
||||
country character varying(100),
|
||||
city character varying(100),
|
||||
id integer NOT NULL,
|
||||
department_id integer,
|
||||
departmnt character varying(100)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.employee OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: employee_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.employee_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.employee_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: employee_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.employee_id_seq OWNED BY public.employee.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: film_film_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.film_film_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.film_film_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: inventory_inventory_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.inventory_inventory_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.inventory_inventory_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: language_language_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.language_language_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.language_language_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: payment_payment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.payment_payment_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.payment_payment_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: rental_rental_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.rental_rental_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.rental_rental_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: staff_staff_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.staff_staff_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.staff_staff_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: store_store_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.store_store_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.store_store_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: employee id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employee ALTER COLUMN id SET DEFAULT nextval('public.employee_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: employee employee_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.employee
|
||||
ADD CONSTRAINT employee_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: pg_database_owner
|
||||
--
|
||||
|
||||
REVOKE USAGE ON SCHEMA public FROM PUBLIC;
|
||||
GRANT ALL ON SCHEMA public TO postgres;
|
||||
GRANT ALL ON SCHEMA public TO PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
-- Downloaded from: https://github.com/amittannagit/World-Cup-database-project-files/blob/cb5dec9fd4d74e0d28e2fc60ffd1e726e9eb1a08/worldcup.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
|
||||
-- Dumped by pg_dump version 12.17 (Ubuntu 12.17-1.pgdg22.04+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
DROP DATABASE worldcup;
|
||||
--
|
||||
-- Name: worldcup; Type: DATABASE; Schema: -; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE DATABASE worldcup WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';
|
||||
|
||||
|
||||
ALTER DATABASE worldcup OWNER TO freecodecamp;
|
||||
|
||||
\connect worldcup
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: games; Type: TABLE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE TABLE public.games (
|
||||
game_id integer NOT NULL,
|
||||
year integer NOT NULL,
|
||||
round character varying(50) NOT NULL,
|
||||
winner_id integer NOT NULL,
|
||||
opponent_id integer NOT NULL,
|
||||
winner_goals integer NOT NULL,
|
||||
opponent_goals integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.games OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: games_game_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.games_game_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.games_game_id_seq OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: games_game_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.games_game_id_seq OWNED BY public.games.game_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: teams; Type: TABLE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE TABLE public.teams (
|
||||
team_id integer NOT NULL,
|
||||
name character varying(50) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.teams OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: teams_team_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.teams_team_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER TABLE public.teams_team_id_seq OWNER TO freecodecamp;
|
||||
|
||||
--
|
||||
-- Name: teams_team_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.teams_team_id_seq OWNED BY public.teams.team_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: games game_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games ALTER COLUMN game_id SET DEFAULT nextval('public.games_game_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: teams team_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.teams ALTER COLUMN team_id SET DEFAULT nextval('public.teams_team_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: games; Type: TABLE DATA; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
INSERT INTO public.games VALUES (1, 2018, 'Final', 1, 2, 4, 2);
|
||||
INSERT INTO public.games VALUES (2, 2018, 'Third Place', 3, 4, 2, 0);
|
||||
INSERT INTO public.games VALUES (3, 2018, 'Semi-Final', 2, 4, 2, 1);
|
||||
INSERT INTO public.games VALUES (4, 2018, 'Semi-Final', 1, 3, 1, 0);
|
||||
INSERT INTO public.games VALUES (5, 2018, 'Quarter-Final', 2, 10, 3, 2);
|
||||
INSERT INTO public.games VALUES (6, 2018, 'Quarter-Final', 4, 12, 2, 0);
|
||||
INSERT INTO public.games VALUES (7, 2018, 'Quarter-Final', 3, 14, 2, 1);
|
||||
INSERT INTO public.games VALUES (8, 2018, 'Quarter-Final', 1, 16, 2, 0);
|
||||
INSERT INTO public.games VALUES (9, 2018, 'Eighth-Final', 4, 18, 2, 1);
|
||||
INSERT INTO public.games VALUES (10, 2018, 'Eighth-Final', 12, 20, 1, 0);
|
||||
INSERT INTO public.games VALUES (11, 2018, 'Eighth-Final', 3, 22, 3, 2);
|
||||
INSERT INTO public.games VALUES (12, 2018, 'Eighth-Final', 14, 24, 2, 0);
|
||||
INSERT INTO public.games VALUES (13, 2018, 'Eighth-Final', 2, 26, 2, 1);
|
||||
INSERT INTO public.games VALUES (14, 2018, 'Eighth-Final', 10, 28, 2, 1);
|
||||
INSERT INTO public.games VALUES (15, 2018, 'Eighth-Final', 16, 30, 2, 1);
|
||||
INSERT INTO public.games VALUES (16, 2018, 'Eighth-Final', 1, 32, 4, 3);
|
||||
INSERT INTO public.games VALUES (17, 2014, 'Final', 33, 32, 1, 0);
|
||||
INSERT INTO public.games VALUES (18, 2014, 'Third Place', 35, 14, 3, 0);
|
||||
INSERT INTO public.games VALUES (19, 2014, 'Semi-Final', 32, 35, 1, 0);
|
||||
INSERT INTO public.games VALUES (20, 2014, 'Semi-Final', 33, 14, 7, 1);
|
||||
INSERT INTO public.games VALUES (21, 2014, 'Quarter-Final', 35, 42, 1, 0);
|
||||
INSERT INTO public.games VALUES (22, 2014, 'Quarter-Final', 32, 3, 1, 0);
|
||||
INSERT INTO public.games VALUES (23, 2014, 'Quarter-Final', 14, 18, 2, 1);
|
||||
INSERT INTO public.games VALUES (24, 2014, 'Quarter-Final', 33, 1, 1, 0);
|
||||
INSERT INTO public.games VALUES (25, 2014, 'Eighth-Final', 14, 50, 2, 1);
|
||||
INSERT INTO public.games VALUES (26, 2014, 'Eighth-Final', 18, 16, 2, 0);
|
||||
INSERT INTO public.games VALUES (27, 2014, 'Eighth-Final', 1, 54, 2, 0);
|
||||
INSERT INTO public.games VALUES (28, 2014, 'Eighth-Final', 33, 56, 2, 1);
|
||||
INSERT INTO public.games VALUES (29, 2014, 'Eighth-Final', 35, 24, 2, 1);
|
||||
INSERT INTO public.games VALUES (30, 2014, 'Eighth-Final', 42, 60, 2, 1);
|
||||
INSERT INTO public.games VALUES (31, 2014, 'Eighth-Final', 32, 20, 1, 0);
|
||||
INSERT INTO public.games VALUES (32, 2014, 'Eighth-Final', 3, 64, 2, 1);
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: teams; Type: TABLE DATA; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
INSERT INTO public.teams VALUES (1, 'France');
|
||||
INSERT INTO public.teams VALUES (2, 'Croatia');
|
||||
INSERT INTO public.teams VALUES (3, 'Belgium');
|
||||
INSERT INTO public.teams VALUES (4, 'England');
|
||||
INSERT INTO public.teams VALUES (10, 'Russia');
|
||||
INSERT INTO public.teams VALUES (12, 'Sweden');
|
||||
INSERT INTO public.teams VALUES (14, 'Brazil');
|
||||
INSERT INTO public.teams VALUES (16, 'Uruguay');
|
||||
INSERT INTO public.teams VALUES (18, 'Colombia');
|
||||
INSERT INTO public.teams VALUES (20, 'Switzerland');
|
||||
INSERT INTO public.teams VALUES (22, 'Japan');
|
||||
INSERT INTO public.teams VALUES (24, 'Mexico');
|
||||
INSERT INTO public.teams VALUES (26, 'Denmark');
|
||||
INSERT INTO public.teams VALUES (28, 'Spain');
|
||||
INSERT INTO public.teams VALUES (30, 'Portugal');
|
||||
INSERT INTO public.teams VALUES (32, 'Argentina');
|
||||
INSERT INTO public.teams VALUES (33, 'Germany');
|
||||
INSERT INTO public.teams VALUES (35, 'Netherlands');
|
||||
INSERT INTO public.teams VALUES (42, 'Costa Rica');
|
||||
INSERT INTO public.teams VALUES (50, 'Chile');
|
||||
INSERT INTO public.teams VALUES (54, 'Nigeria');
|
||||
INSERT INTO public.teams VALUES (56, 'Algeria');
|
||||
INSERT INTO public.teams VALUES (60, 'Greece');
|
||||
INSERT INTO public.teams VALUES (64, 'United States');
|
||||
|
||||
|
||||
--
|
||||
-- Name: games_game_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.games_game_id_seq', 32, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: teams_team_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.teams_team_id_seq', 64, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: games games_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games
|
||||
ADD CONSTRAINT games_pkey PRIMARY KEY (game_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: teams teams_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.teams
|
||||
ADD CONSTRAINT teams_name_key UNIQUE (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: teams teams_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.teams
|
||||
ADD CONSTRAINT teams_pkey PRIMARY KEY (team_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: games games_opponent_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games
|
||||
ADD CONSTRAINT games_opponent_id_fkey FOREIGN KEY (opponent_id) REFERENCES public.teams(team_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: games games_winner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.games
|
||||
ADD CONSTRAINT games_winner_id_fkey FOREIGN KEY (winner_id) REFERENCES public.teams(team_id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,243 @@
|
||||
-- Downloaded from: https://github.com/bartr/agency/blob/9e8f7185023b3616a144f56b0bbbc0f7cb89b37d/sql/cnp.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 13.4 (Debian 13.4-4.pgdg110+1)
|
||||
-- Dumped by pg_dump version 13.4 (Debian 13.4-4.pgdg110+1)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
SET default_tablespace = '';
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: update_modified(); Type: FUNCTION; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.update_modified() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.modified_ = now();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.update_modified() OWNER TO root;
|
||||
|
||||
--
|
||||
-- Name: children; Type: TABLE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE TABLE public.children (
|
||||
parentid integer NOT NULL,
|
||||
childid integer NOT NULL,
|
||||
sortorder integer DEFAULT 100
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.children OWNER TO root;
|
||||
|
||||
--
|
||||
-- Name: links; Type: TABLE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE TABLE public.links (
|
||||
id integer NOT NULL,
|
||||
path character varying(400) NOT NULL,
|
||||
type integer NOT NULL,
|
||||
description character varying(64000) NOT NULL,
|
||||
owner character varying(100) NOT NULL,
|
||||
target character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
content character varying(64000) DEFAULT ''::character varying NOT NULL,
|
||||
isprivate boolean DEFAULT false NOT NULL,
|
||||
created_ timestamp(0) with time zone DEFAULT now() NOT NULL,
|
||||
modified_ timestamp(0) with time zone DEFAULT now() NOT NULL,
|
||||
title character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
tags json DEFAULT '[]'::json NOT NULL,
|
||||
template character varying(16000) DEFAULT ''::character varying NOT NULL,
|
||||
html character varying(64000) DEFAULT ''::character varying NOT NULL,
|
||||
orderby character varying(8000) DEFAULT ''::character varying NOT NULL,
|
||||
tenant character varying(100) DEFAULT '*'::character varying NOT NULL,
|
||||
sortorder integer DEFAULT 100 NOT NULL,
|
||||
theme character varying(400) DEFAULT 'blue'::character varying NOT NULL,
|
||||
title2 character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
thumbnail character varying(400) DEFAULT ''::character varying,
|
||||
background character varying(400) DEFAULT ''::character varying,
|
||||
facebook character varying(200) DEFAULT ''::character varying,
|
||||
github character varying(200) DEFAULT ''::character varying,
|
||||
instagram character varying(200) DEFAULT ''::character varying,
|
||||
linkedin character varying(200) DEFAULT ''::character varying,
|
||||
twitter character varying(200) DEFAULT ''::character varying,
|
||||
youtube character varying(200) DEFAULT ''::character varying,
|
||||
web character varying(200) DEFAULT ''::character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.links OWNER TO root;
|
||||
|
||||
--
|
||||
-- Name: links_id_seq; Type: SEQUENCE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE public.links ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME public.links_id_seq
|
||||
START WITH 101
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: logs; Type: TABLE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE TABLE public.logs (
|
||||
id integer NOT NULL,
|
||||
date timestamp(3) with time zone NOT NULL,
|
||||
statuscode integer NOT NULL,
|
||||
path character varying(400) NOT NULL,
|
||||
duration integer NOT NULL,
|
||||
contentlength integer NOT NULL,
|
||||
method character varying(10) NOT NULL,
|
||||
host character varying(100) DEFAULT ''::character varying NOT NULL,
|
||||
ipaddress character varying(20) DEFAULT ''::character varying NOT NULL,
|
||||
querystring character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
referrer character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
useragent character varying(400) DEFAULT ''::character varying NOT NULL,
|
||||
ismobile boolean DEFAULT false NOT NULL,
|
||||
userid character varying(100) DEFAULT ''::character varying NOT NULL,
|
||||
category character varying(100) DEFAULT ''::character varying NOT NULL,
|
||||
tag character varying(100) DEFAULT ''::character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.logs OWNER TO root;
|
||||
|
||||
--
|
||||
-- Name: logs_id_seq; Type: SEQUENCE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE public.logs ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY (
|
||||
SEQUENCE NAME public.logs_id_seq
|
||||
START WITH 101
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users; Type: TABLE; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE TABLE public.users (
|
||||
id character varying(50) NOT NULL,
|
||||
isadmin boolean DEFAULT false NOT NULL,
|
||||
token character varying(200) DEFAULT ''::character varying NOT NULL,
|
||||
cookie character varying(200) DEFAULT ''::character varying NOT NULL,
|
||||
github character varying(200) DEFAULT ''::character varying NOT NULL,
|
||||
linkedin character varying(200) DEFAULT ''::character varying NOT NULL,
|
||||
twitter character varying(200) DEFAULT ''::character varying NOT NULL,
|
||||
facebook character varying(200) DEFAULT ''::character varying,
|
||||
instagram character varying(200) DEFAULT ''::character varying,
|
||||
youtube character varying(200) DEFAULT ''::character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.users OWNER TO root;
|
||||
|
||||
--
|
||||
-- Data for Name: children; Type: TABLE DATA; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
COPY public.children (parentid, childid, sortorder) FROM stdin;
|
||||
0 101 1
|
||||
0 103 100
|
||||
0 104 100
|
||||
101 102 100
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: links; Type: TABLE DATA; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
COPY public.links (id, path, type, description, owner, target, content, isprivate, created_, modified_, title, tags, template, html, orderby, tenant, sortorder, theme, title2, thumbnail, background, facebook, github, instagram, linkedin, twitter, youtube, web) FROM stdin;
|
||||
0 / 0 <h1>Welcome to CNP Labs</h1>Under construction ... cnp Welcome to CNP Labs Under construction f 2021-11-09 21:02:18+00 2021-11-09 21:28:38+00 CNP Labs [] cnp-tree cnp.dev 100 orange https://cnp.dev/github
|
||||
1 /github 1 CNP Labs GitHub cnp https://github.com/cnp-labs /github\nCNP Labs GitHub\nhttps://github.com/cnp-labs\nCNP Labs GitHub f 2021-11-09 21:15:16+00 2021-11-09 21:28:38+00 CNP Labs GitHub [] cnp.dev 100 orange
|
||||
2 /gh 1 CNP Labs GitHub cnp https://github.com/cnp-labs /gh\nCNP Labs GitHub\nhttps://github.com/cnp-labs\nCNP Labs GitHub f 2021-11-09 21:15:31+00 2021-11-09 21:28:38+00 CNP Labs GitHub [] cnp.dev 100 orange
|
||||
101 /demos 0 Demo videos cnp /demos\nDemo Videos\nDemo videos f 2021-11-09 21:10:32+00 2021-11-09 21:30:16+00 Demo Videos [] cnp-tree cnp.dev 1 orange CNP Labs
|
||||
102 /demos/devx 1 CNP Labs Developer Experience Demo Video cnp https://cnp.dev/cnp/content/CNP-Labs-DevX.mp4 DevX Demo CNP Labs Developer Experience Demo Video f 2021-11-09 21:11:25+00 2021-11-09 21:28:38+00 DevX Demo [] cnp.dev 100 orange
|
||||
103 /blog 0 CNP Labs Blog cnp /blog\nOur Blog\nCNP Labs Blog f 2021-11-09 21:24:12+00 2021-11-09 21:28:57+00 Our Blog [] cnp-tree Under Construction cnp.dev 100 orange CNP Labs
|
||||
104 /about 0 About CNP Labs cnp /about\nAbout Us\nAbout CNP Labs f 2021-11-09 21:24:33+00 2021-11-09 21:28:57+00 About Us [] cnp-tree About CNP Labs cnp.dev 100 orange CNP Labs
|
||||
\.
|
||||
|
||||
--
|
||||
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
COPY public.users (id, isadmin, token, github) FROM stdin;
|
||||
bartr t Table512
|
||||
matt t Agency512
|
||||
cnp t 512Table https://github.com/cnp-labs
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: links_id_seq; Type: SEQUENCE SET; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.links_id_seq', 105, true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: children children_pkey; Type: CONSTRAINT; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.children
|
||||
ADD CONSTRAINT children_pkey PRIMARY KEY (parentid, childid);
|
||||
|
||||
|
||||
--
|
||||
-- Name: links links_pkey; Type: CONSTRAINT; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.links
|
||||
ADD CONSTRAINT links_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: logs logs_pkey; Type: CONSTRAINT; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.logs
|
||||
ADD CONSTRAINT logs_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: links modified_trigger; Type: TRIGGER; Schema: public; Owner: root
|
||||
--
|
||||
|
||||
CREATE TRIGGER modified_trigger BEFORE UPDATE ON public.links FOR EACH ROW EXECUTE FUNCTION public.update_modified();
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,287 @@
|
||||
-- Downloaded from: https://github.com/by-zah/universityScheduleBot/blob/c8e0034ca23d8f0cac3c0ae6d5f4968ebb4be207/emptyDump.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 12.3 (Ubuntu 12.3-1.pgdg16.04+1)
|
||||
-- Dumped by pg_dump version 12.4
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
DROP DATABASE IF EXISTS d7tmbubts2qa9a;
|
||||
--
|
||||
-- Name: d7tmbubts2qa9a; Type: DATABASE; Schema: -; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE DATABASE d7tmbubts2qa9a WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
|
||||
|
||||
|
||||
ALTER DATABASE d7tmbubts2qa9a OWNER TO hayrdyszkbigyi;
|
||||
|
||||
\connect d7tmbubts2qa9a
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: public; Type: SCHEMA; Schema: -; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE SCHEMA public;
|
||||
|
||||
|
||||
ALTER SCHEMA public OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COMMENT ON SCHEMA public IS 'standard public schema';
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: classes; Type: TABLE; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE TABLE public.classes (
|
||||
index integer NOT NULL,
|
||||
group_name character varying(255) NOT NULL,
|
||||
day integer NOT NULL,
|
||||
building character varying(255),
|
||||
name character varying(255),
|
||||
room_number character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.classes OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Name: groups; Type: TABLE; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE TABLE public.groups (
|
||||
name character varying(255) NOT NULL,
|
||||
owner_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.groups OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Name: schedule; Type: TABLE; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE TABLE public.schedule (
|
||||
index integer NOT NULL,
|
||||
end_hour integer,
|
||||
end_min integer,
|
||||
start_hour integer,
|
||||
start_min integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.schedule OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Name: subscriptions; Type: TABLE; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE TABLE public.subscriptions (
|
||||
user_chat_id bigint NOT NULL,
|
||||
"group" character varying(255) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.subscriptions OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Name: users; Type: TABLE; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE TABLE public.users (
|
||||
id integer NOT NULL,
|
||||
chat_id bigint NOT NULL,
|
||||
interfaculty_discipline character varying(255),
|
||||
local character varying(255),
|
||||
is_supper boolean DEFAULT false
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.users OWNER TO hayrdyszkbigyi;
|
||||
|
||||
--
|
||||
-- Data for Name: classes; Type: TABLE DATA; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COPY public.classes (index, group_name, day, building, name, room_number) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: groups; Type: TABLE DATA; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COPY public.groups (name, owner_id) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: schedule; Type: TABLE DATA; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COPY public.schedule (index, end_hour, end_min, start_hour, start_min) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: subscriptions; Type: TABLE DATA; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COPY public.subscriptions (user_chat_id, "group") FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
COPY public.users (id, chat_id, interfaculty_discipline, local, is_supper) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: classes classes_pkey; Type: CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.classes
|
||||
ADD CONSTRAINT classes_pkey PRIMARY KEY (index, group_name, day);
|
||||
|
||||
|
||||
--
|
||||
-- Name: groups groups_pkey; Type: CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.groups
|
||||
ADD CONSTRAINT groups_pkey PRIMARY KEY (name);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schedule schedule_pkey; Type: CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.schedule
|
||||
ADD CONSTRAINT schedule_pkey PRIMARY KEY (index);
|
||||
|
||||
|
||||
--
|
||||
-- Name: subscriptions subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.subscriptions
|
||||
ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (user_chat_id, "group");
|
||||
|
||||
|
||||
--
|
||||
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.users
|
||||
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: users_chat_id_uindex; Type: INDEX; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX users_chat_id_uindex ON public.users USING btree (chat_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: classes classes_groups_name_fk; Type: FK CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.classes
|
||||
ADD CONSTRAINT classes_groups_name_fk FOREIGN KEY (group_name) REFERENCES public.groups(name) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- Name: classes classes_schedule_index_fk; Type: FK CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.classes
|
||||
ADD CONSTRAINT classes_schedule_index_fk FOREIGN KEY (index) REFERENCES public.schedule(index);
|
||||
|
||||
|
||||
--
|
||||
-- Name: groups groups_users_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.groups
|
||||
ADD CONSTRAINT groups_users_id_fk FOREIGN KEY (owner_id) REFERENCES public.users(id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- Name: subscriptions subscriptions_groups_name_fk; Type: FK CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.subscriptions
|
||||
ADD CONSTRAINT subscriptions_groups_name_fk FOREIGN KEY ("group") REFERENCES public.groups(name) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- Name: subscriptions subscriptions_users_chat_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.subscriptions
|
||||
ADD CONSTRAINT subscriptions_users_chat_id_fk FOREIGN KEY (user_chat_id) REFERENCES public.users(chat_id) ON UPDATE CASCADE ON DELETE RESTRICT;
|
||||
|
||||
|
||||
--
|
||||
-- Name: DATABASE d7tmbubts2qa9a; Type: ACL; Schema: -; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
REVOKE CONNECT,TEMPORARY ON DATABASE d7tmbubts2qa9a FROM PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner: hayrdyszkbigyi
|
||||
--
|
||||
|
||||
REVOKE ALL ON SCHEMA public FROM postgres;
|
||||
REVOKE ALL ON SCHEMA public FROM PUBLIC;
|
||||
GRANT ALL ON SCHEMA public TO hayrdyszkbigyi;
|
||||
GRANT ALL ON SCHEMA public TO PUBLIC;
|
||||
|
||||
|
||||
--
|
||||
-- Name: LANGUAGE plpgsql; Type: ACL; Schema: -; Owner: postgres
|
||||
--
|
||||
|
||||
GRANT ALL ON LANGUAGE plpgsql TO hayrdyszkbigyi;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,363 @@
|
||||
-- Downloaded from: https://github.com/dbarrera98/proyecto-informa/blob/f6d6e700a5f20ffa272f728a83af6eb3683c3b83/initdb/init.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 16.1
|
||||
-- Dumped by pg_dump version 16.1
|
||||
|
||||
-- Started on 2025-05-31 16:18:14
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- TOC entry 224 (class 1255 OID 24614)
|
||||
-- Name: actualizar_autor(integer, character varying); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.actualizar_autor(p_id integer, p_nombre character varying) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM autores a WHERE a.id = p_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Autor no existe';
|
||||
END IF;
|
||||
UPDATE autores a SET nombre = p_nombre WHERE a.id = p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.actualizar_autor(p_id integer, p_nombre character varying) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 225 (class 1255 OID 24610)
|
||||
-- Name: actualizar_libro(integer, character varying, integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.actualizar_libro(p_id integer, p_titulo character varying, p_autor_id integer) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM autores a WHERE a.id = p_autor_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Autor no existe';
|
||||
END IF;
|
||||
SELECT COUNT(*) INTO v_count FROM libros l WHERE l.id = p_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Libro no existe';
|
||||
END IF;
|
||||
UPDATE libros l SET titulo = p_titulo, autor_id = p_autor_id WHERE l.id = p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.actualizar_libro(p_id integer, p_titulo character varying, p_autor_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 223 (class 1255 OID 24616)
|
||||
-- Name: consultar_autor(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.consultar_autor(p_id integer) RETURNS TABLE(id integer, nombre character varying)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT a.id, a.nombre FROM autores a WHERE a.id = p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.consultar_autor(p_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 222 (class 1255 OID 24617)
|
||||
-- Name: consultar_autores(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.consultar_autores() RETURNS TABLE(id integer, nombre character varying)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY
|
||||
SELECT a.id, a.nombre FROM autores a;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.consultar_autores() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 220 (class 1255 OID 24612)
|
||||
-- Name: consultar_libro(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.consultar_libro(p_id integer) RETURNS TABLE(id integer, titulo character varying, autor_id integer)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT l.id, l.titulo, l.autor_id FROM libros l WHERE l.id = p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.consultar_libro(p_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 226 (class 1255 OID 24613)
|
||||
-- Name: consultar_libros(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.consultar_libros() RETURNS TABLE(id integer, titulo character varying, autor_id integer)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
RETURN QUERY SELECT l.id, l.titulo, l.autor_id FROM libros l;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.consultar_libros() OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 232 (class 1255 OID 24615)
|
||||
-- Name: eliminar_autor(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.eliminar_autor(p_id integer) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM autores a WHERE a.id = p_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Autor no existe';
|
||||
END IF;
|
||||
SELECT COUNT(*) INTO v_count FROM libros l WHERE l.autor_id = p_id;
|
||||
IF v_count > 0 THEN
|
||||
RAISE EXCEPTION 'No se puede eliminar el autor porque tiene libros asociados';
|
||||
END IF;
|
||||
DELETE FROM autores a WHERE a.id = p_id;
|
||||
RAISE NOTICE 'Autor eliminado exitosamente (id = %)', p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.eliminar_autor(p_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 221 (class 1255 OID 24611)
|
||||
-- Name: eliminar_libro(integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.eliminar_libro(p_id integer) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM libros l WHERE l.id = p_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Libro no existe';
|
||||
END IF;
|
||||
DELETE FROM libros l WHERE l.id = p_id;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.eliminar_libro(p_id integer) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 219 (class 1255 OID 24608)
|
||||
-- Name: insertar_autor(character varying); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.insertar_autor(p_nombre character varying) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
INSERT INTO autores (nombre) VALUES (p_nombre);
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.insertar_autor(p_nombre character varying) OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 227 (class 1255 OID 24609)
|
||||
-- Name: insertar_libro(character varying, integer); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.insertar_libro(p_titulo character varying, p_autor_id integer) RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
v_count INTEGER;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO v_count FROM autores a WHERE a.id = p_autor_id;
|
||||
IF v_count = 0 THEN
|
||||
RAISE EXCEPTION 'Autor no existe';
|
||||
END IF;
|
||||
INSERT INTO libros (titulo, autor_id) VALUES (p_titulo, p_autor_id);
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.insertar_libro(p_titulo character varying, p_autor_id integer) OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- TOC entry 216 (class 1259 OID 24592)
|
||||
-- Name: autores; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.autores (
|
||||
id integer NOT NULL,
|
||||
nombre character varying(100) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.autores OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 215 (class 1259 OID 24591)
|
||||
-- Name: autores_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.autores ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.autores_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 218 (class 1259 OID 24598)
|
||||
-- Name: libros; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.libros (
|
||||
id integer NOT NULL,
|
||||
titulo character varying(200) NOT NULL,
|
||||
autor_id integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.libros OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- TOC entry 217 (class 1259 OID 24597)
|
||||
-- Name: libros_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE public.libros ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
|
||||
SEQUENCE NAME public.libros_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4798 (class 0 OID 24592)
|
||||
-- Dependencies: 216
|
||||
-- Data for Name: autores; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.autores (id, nombre) FROM stdin;
|
||||
8 Camilo
|
||||
5 Andres
|
||||
12 William
|
||||
13 Jane
|
||||
11 Cervantes
|
||||
14 Mary
|
||||
15 Laura
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4800 (class 0 OID 24598)
|
||||
-- Dependencies: 218
|
||||
-- Data for Name: libros; Type: TABLE DATA; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
COPY public.libros (id, titulo, autor_id) FROM stdin;
|
||||
4 Don Quijote de la Mancha 11
|
||||
6 Frankenstein 14
|
||||
8 Los caracoles 15
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4806 (class 0 OID 0)
|
||||
-- Dependencies: 215
|
||||
-- Name: autores_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.autores_id_seq', 15, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4807 (class 0 OID 0)
|
||||
-- Dependencies: 217
|
||||
-- Name: libros_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
SELECT pg_catalog.setval('public.libros_id_seq', 8, true);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4650 (class 2606 OID 24596)
|
||||
-- Name: autores autores_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.autores
|
||||
ADD CONSTRAINT autores_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4652 (class 2606 OID 24602)
|
||||
-- Name: libros libros_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.libros
|
||||
ADD CONSTRAINT libros_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- TOC entry 4653 (class 2606 OID 24603)
|
||||
-- Name: libros libros_autor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.libros
|
||||
ADD CONSTRAINT libros_autor_id_fkey FOREIGN KEY (autor_id) REFERENCES public.autores(id);
|
||||
|
||||
|
||||
-- Completed on 2025-05-31 16:18:17
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,826 @@
|
||||
-- Downloaded from: https://github.com/gabrundo/Progetto-Basi-Dati/blob/f8270e116533e237f55d1ef56bcd7a0a0f94f17b/dump_uni.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 11.19
|
||||
-- Dumped by pg_dump version 11.19
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: uni; Type: SCHEMA; Schema: -; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE SCHEMA uni;
|
||||
|
||||
|
||||
ALTER SCHEMA uni OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: anno_insegnamento(); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.anno_insegnamento() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
declare
|
||||
tipo corso_laurea.tipologia%type;
|
||||
begin
|
||||
select tipologia into tipo
|
||||
from corso_laurea
|
||||
where nome = new.corso_laurea;
|
||||
|
||||
if tipo = 'Triennale' then
|
||||
if not (new.anno = '1' or new.anno = '2' or new.anno = '3') then
|
||||
raise exception 'Inserimento del insegnamento % non valido!', new.nome;
|
||||
return null;
|
||||
end if;
|
||||
elsif tipo = 'Magistrale' then
|
||||
if not (new.anno = '1' or new.anno = '2') then
|
||||
raise exception 'Inserimento del insegnamento % non valido!', new.nome;
|
||||
return null;
|
||||
end if;
|
||||
end if;
|
||||
return new;
|
||||
end;
|
||||
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.anno_insegnamento() OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: appelli_esami(); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.appelli_esami() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
declare
|
||||
anno_esame insegnamento.anno%type;
|
||||
begin
|
||||
select anno into anno_esame
|
||||
from insegnamento
|
||||
where corso_laurea = new.corso_laurea and codice = new.codice;
|
||||
|
||||
perform *
|
||||
from insegnamento i inner join appello a on a.corso_laurea = i.corso_laurea and a.codice = i.codice
|
||||
where i.corso_laurea = new.corso_laurea and i.anno = anno_esame and data = new.data;
|
||||
|
||||
if found then
|
||||
raise exception 'Impossibile inserire appello per una sovrapposizione';
|
||||
return null;
|
||||
else
|
||||
return new;
|
||||
end if;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.appelli_esami() OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: descrizione_corso_laurea(character varying); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.descrizione_corso_laurea(character varying) RETURNS text
|
||||
LANGUAGE plpgsql
|
||||
AS $_$
|
||||
declare
|
||||
descrizione text = '';
|
||||
corso corso_laurea%rowtype;
|
||||
ins insegnamento%rowtype;
|
||||
begin
|
||||
select * into corso
|
||||
from corso_laurea
|
||||
where trim(lower(nome)) = trim(lower($1));
|
||||
|
||||
if not found then
|
||||
raise exception 'Nome del corso non trovato';
|
||||
else
|
||||
descrizione = descrizione || 'Nome corso di laurea: ' || corso.nome
|
||||
|| ', tipologia: ' || corso.tipologia || ', facoltà: ' || corso.segreteria || E'\n';
|
||||
for ins in
|
||||
select *
|
||||
from insegnamento
|
||||
where trim(lower(nome)) = trim(lower($1))
|
||||
order by anno asc
|
||||
loop
|
||||
descrizione = descrizione || 'nome esame: ' || ins.nome
|
||||
|| ', anno di erogazione : ' || ins.anno || ', descrizione: ' || ins.descrizione
|
||||
|| ', responsabile: ' || ins.responsabile || E'\n';
|
||||
end loop;
|
||||
end if;
|
||||
return descrizione;
|
||||
end;
|
||||
$_$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.descrizione_corso_laurea(character varying) OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: iscrizione_esami(); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.iscrizione_esami() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
declare
|
||||
cois propedeuticita.corso_is%type;
|
||||
cdis propedeuticita.codice_is%type;
|
||||
begin
|
||||
perform *
|
||||
from insegnamento
|
||||
where corso_laurea = new.corso_laurea and codice = new.codice;
|
||||
|
||||
if found then
|
||||
for cois, cdis in
|
||||
select corso_is, codice_is
|
||||
from propedeuticita
|
||||
where corso_has = new.corso_laurea and codice_has = new.codice
|
||||
|
||||
loop
|
||||
if found then
|
||||
perform *
|
||||
from sostiene
|
||||
where corso_laurea = cois and codice = cdis
|
||||
and studente = new.studente and voto > 17 and data < new.data;
|
||||
|
||||
if not found then
|
||||
raise exception 'Propedeuticità non rispettate per il corso %', cois;
|
||||
return null;
|
||||
end if;
|
||||
end if;
|
||||
end loop;
|
||||
else
|
||||
raise info 'Insegnamento % non registrato', cois;
|
||||
return null;
|
||||
end if;
|
||||
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.iscrizione_esami() OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: numero_insegnamenti_docente(); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.numero_insegnamenti_docente() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
declare
|
||||
resp insegnamento.responsabile%type;
|
||||
numero numeric;
|
||||
begin
|
||||
select responsabile, count(*) into resp, numero
|
||||
from insegnamento
|
||||
group by responsabile
|
||||
having count(*) > 3;
|
||||
|
||||
if found then
|
||||
raise exception 'Il docente, con identificativo %, non può gestire altri corsi!', resp;
|
||||
delete from insegnamento where corso_laurea = new.corso_laurea and codice = new.codice;
|
||||
end if;
|
||||
return null;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.numero_insegnamenti_docente() OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: str_studente_carriera(); Type: FUNCTION; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE FUNCTION uni.str_studente_carriera() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
begin
|
||||
insert into str_studente (matricola, email, nome, cognome, corso_laurea)
|
||||
values (old.matricola, old.email, old.nome, old.cognome, old.corso_laurea);
|
||||
|
||||
insert into str_sostiene
|
||||
select *
|
||||
from sostiene
|
||||
where studente = old.matricola;
|
||||
|
||||
delete
|
||||
from sostiene
|
||||
where studente=old.matricola;
|
||||
|
||||
return old;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION uni.str_studente_carriera() OWNER TO bitnami;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_with_oids = false;
|
||||
|
||||
--
|
||||
-- Name: appello; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.appello (
|
||||
corso_laurea character varying NOT NULL,
|
||||
codice character(3) NOT NULL,
|
||||
data date NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.appello OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: insegnamento; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.insegnamento (
|
||||
corso_laurea character varying NOT NULL,
|
||||
codice character(3) NOT NULL,
|
||||
nome character varying NOT NULL,
|
||||
anno character(1) NOT NULL,
|
||||
descrizione text NOT NULL,
|
||||
responsabile character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.insegnamento OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: sostiene; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.sostiene (
|
||||
studente character(6) NOT NULL,
|
||||
corso_laurea character varying NOT NULL,
|
||||
codice character(3) NOT NULL,
|
||||
data date NOT NULL,
|
||||
voto smallint,
|
||||
CONSTRAINT voto_valido CHECK (((0 <= voto) AND (voto <= 30)))
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.sostiene OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: carriera_completa; Type: VIEW; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE VIEW uni.carriera_completa AS
|
||||
SELECT s.studente,
|
||||
i.nome,
|
||||
a.corso_laurea,
|
||||
i.anno,
|
||||
a.data,
|
||||
s.voto
|
||||
FROM ((uni.appello a
|
||||
JOIN uni.sostiene s ON ((((a.corso_laurea)::text = (s.corso_laurea)::text) AND (a.codice = s.codice) AND (a.data = s.data))))
|
||||
JOIN uni.insegnamento i ON ((((a.corso_laurea)::text = (i.corso_laurea)::text) AND (a.codice = i.codice))));
|
||||
|
||||
|
||||
ALTER TABLE uni.carriera_completa OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: str_sostiene; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.str_sostiene (
|
||||
studente character(6) NOT NULL,
|
||||
corso_laurea character varying NOT NULL,
|
||||
codice character(3) NOT NULL,
|
||||
data date NOT NULL,
|
||||
voto smallint
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.str_sostiene OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: carriera_completa_globale; Type: VIEW; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE VIEW uni.carriera_completa_globale AS
|
||||
WITH sostiene_globale AS (
|
||||
SELECT sostiene.studente,
|
||||
sostiene.corso_laurea,
|
||||
sostiene.codice,
|
||||
sostiene.data,
|
||||
sostiene.voto
|
||||
FROM uni.sostiene
|
||||
UNION
|
||||
SELECT str_sostiene.studente,
|
||||
str_sostiene.corso_laurea,
|
||||
str_sostiene.codice,
|
||||
str_sostiene.data,
|
||||
str_sostiene.voto
|
||||
FROM uni.str_sostiene
|
||||
)
|
||||
SELECT s.studente,
|
||||
i.nome,
|
||||
a.corso_laurea,
|
||||
i.anno,
|
||||
a.data,
|
||||
s.voto
|
||||
FROM ((uni.appello a
|
||||
JOIN sostiene_globale s ON ((((a.corso_laurea)::text = (s.corso_laurea)::text) AND (a.codice = s.codice) AND (a.data = s.data))))
|
||||
JOIN uni.insegnamento i ON ((((a.corso_laurea)::text = (i.corso_laurea)::text) AND (a.codice = i.codice))));
|
||||
|
||||
|
||||
ALTER TABLE uni.carriera_completa_globale OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: carriera_valida; Type: VIEW; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE VIEW uni.carriera_valida AS
|
||||
WITH esami_recenti AS (
|
||||
SELECT carriera_completa.studente,
|
||||
carriera_completa.nome,
|
||||
carriera_completa.corso_laurea,
|
||||
carriera_completa.anno,
|
||||
max(carriera_completa.data) AS data_recente
|
||||
FROM uni.carriera_completa
|
||||
WHERE (carriera_completa.voto > 17)
|
||||
GROUP BY carriera_completa.studente, carriera_completa.nome, carriera_completa.corso_laurea, carriera_completa.anno
|
||||
)
|
||||
SELECT e.studente,
|
||||
e.nome,
|
||||
e.corso_laurea,
|
||||
e.anno,
|
||||
e.data_recente,
|
||||
c.voto
|
||||
FROM (esami_recenti e
|
||||
JOIN uni.carriera_completa c ON (((e.studente = c.studente) AND ((e.nome)::text = (c.nome)::text) AND ((e.corso_laurea)::text = (c.corso_laurea)::text) AND (e.data_recente = c.data))));
|
||||
|
||||
|
||||
ALTER TABLE uni.carriera_valida OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: carriera_valida_globale; Type: VIEW; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE VIEW uni.carriera_valida_globale AS
|
||||
WITH esami_recenti_globali AS (
|
||||
SELECT carriera_completa_globale.studente,
|
||||
carriera_completa_globale.nome,
|
||||
carriera_completa_globale.corso_laurea,
|
||||
carriera_completa_globale.anno,
|
||||
max(carriera_completa_globale.data) AS data_recente
|
||||
FROM uni.carriera_completa_globale
|
||||
WHERE (carriera_completa_globale.voto > 17)
|
||||
GROUP BY carriera_completa_globale.studente, carriera_completa_globale.nome, carriera_completa_globale.corso_laurea, carriera_completa_globale.anno
|
||||
)
|
||||
SELECT e.studente,
|
||||
e.nome,
|
||||
e.corso_laurea,
|
||||
e.anno,
|
||||
e.data_recente,
|
||||
c.voto
|
||||
FROM (esami_recenti_globali e
|
||||
JOIN uni.carriera_completa_globale c ON (((e.studente = c.studente) AND ((e.nome)::text = (c.nome)::text) AND ((e.corso_laurea)::text = (c.corso_laurea)::text) AND (e.data_recente = c.data))));
|
||||
|
||||
|
||||
ALTER TABLE uni.carriera_valida_globale OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: corso_laurea; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.corso_laurea (
|
||||
nome character varying NOT NULL,
|
||||
tipologia character(10) NOT NULL,
|
||||
segreteria character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.corso_laurea OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: docente; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.docente (
|
||||
email character varying NOT NULL,
|
||||
password character varying NOT NULL,
|
||||
nome character varying(50) NOT NULL,
|
||||
cognome character varying(50) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.docente OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: propedeuticita; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.propedeuticita (
|
||||
corso_is character varying NOT NULL,
|
||||
codice_is character(3) NOT NULL,
|
||||
corso_has character varying NOT NULL,
|
||||
codice_has character(3) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.propedeuticita OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: segretario; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.segretario (
|
||||
email character varying NOT NULL,
|
||||
password character varying NOT NULL,
|
||||
nome character varying(50) NOT NULL,
|
||||
cognome character varying(50) NOT NULL,
|
||||
segreteria character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.segretario OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: segreteria; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.segreteria (
|
||||
indirizzo character varying NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.segreteria OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: str_studente; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.str_studente (
|
||||
matricola character(6) NOT NULL,
|
||||
email character varying NOT NULL,
|
||||
nome character varying(50) NOT NULL,
|
||||
cognome character varying(50) NOT NULL,
|
||||
corso_laurea character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.str_studente OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Name: studente; Type: TABLE; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TABLE uni.studente (
|
||||
matricola character(6) NOT NULL,
|
||||
email character varying NOT NULL,
|
||||
password character varying NOT NULL,
|
||||
nome character varying(50) NOT NULL,
|
||||
cognome character varying(50) NOT NULL,
|
||||
corso_laurea character varying
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE uni.studente OWNER TO bitnami;
|
||||
|
||||
--
|
||||
-- Data for Name: appello; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.appello (corso_laurea, codice, data) FROM stdin;
|
||||
Informatica 001 2023-06-15
|
||||
Informatica 001 2023-06-30
|
||||
Informatica 002 2023-07-10
|
||||
Informatica 004 2023-07-10
|
||||
Informatica 004 2023-07-24
|
||||
Informatica 003 2023-07-17
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: corso_laurea; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.corso_laurea (nome, tipologia, segreteria) FROM stdin;
|
||||
Informatica Triennale Scienze e Tecnologie
|
||||
Matematica Magistrale Scienze e Tecnologie
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: docente; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.docente (email, password, nome, cognome) FROM stdin;
|
||||
luca.bianchi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Luca Bianchi
|
||||
giulia.verdi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Giulia Verdi
|
||||
mario.rossi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Mario Rossi
|
||||
giovanni.russo@example.com 6a4dc9133d5f3b6d9fff778aff361961 Giovanni Russo
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: insegnamento; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.insegnamento (corso_laurea, codice, nome, anno, descrizione, responsabile) FROM stdin;
|
||||
Informatica 001 Programmazione 1 Corso introduttivo alla programmazione mario.rossi@example.com
|
||||
Informatica 002 Basi di Dati 2 Intorduzione alle basi di dati luca.bianchi@example.com
|
||||
Matematica 001 Analisi Matematica 1 Corso di analisi matematica avanzata giulia.verdi@example.com
|
||||
Informatica 004 Logica Matematica 1 Introduzione alla logica matematica giulia.verdi@example.com
|
||||
Informatica 003 Matematica del continuo 1 Corso introduttivo di analisi matematica giulia.verdi@example.com
|
||||
Informatica 005 Architettura degli Elaboratori 1 Corso introduttivo alla architettura degli elaboratori giovanni.russo@example.com
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: propedeuticita; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.propedeuticita (corso_is, codice_is, corso_has, codice_has) FROM stdin;
|
||||
Informatica 001 Informatica 002
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: segretario; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.segretario (email, password, nome, cognome, segreteria) FROM stdin;
|
||||
laura.rosa@example.com 6a4dc9133d5f3b6d9fff778aff361961 Laura Rosa Studi Umanistici
|
||||
paolo.neri@example.com 6a4dc9133d5f3b6d9fff778aff361961 Paolo Neri Scienze e Tecnologie
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: segreteria; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.segreteria (indirizzo) FROM stdin;
|
||||
Scienze e Tecnologie
|
||||
Studi Umanistici
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: sostiene; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.sostiene (studente, corso_laurea, codice, data, voto) FROM stdin;
|
||||
789012 Informatica 001 2023-06-30 25
|
||||
789012 Informatica 002 2023-07-10 27
|
||||
123456 Informatica 001 2023-06-15 28
|
||||
123456 Informatica 001 2023-06-30 30
|
||||
123456 Informatica 002 2023-07-10 \N
|
||||
123456 Informatica 004 2023-07-10 20
|
||||
123456 Informatica 003 2023-07-17 27
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: str_sostiene; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.str_sostiene (studente, corso_laurea, codice, data, voto) FROM stdin;
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: str_studente; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.str_studente (matricola, email, nome, cognome, corso_laurea) FROM stdin;
|
||||
345678 sara.rossi@example.com Sara Rossi Matematica
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Data for Name: studente; Type: TABLE DATA; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
COPY uni.studente (matricola, email, password, nome, cognome, corso_laurea) FROM stdin;
|
||||
789012 marco.bianchi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Marco Bianchi Informatica
|
||||
123456 giuseppe.verdi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Giuseppe Verdi Informatica
|
||||
234567 luca.bianchi@example.com 6a4dc9133d5f3b6d9fff778aff361961 Luca Bianchi Informatica
|
||||
\.
|
||||
|
||||
|
||||
--
|
||||
-- Name: appello appello_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.appello
|
||||
ADD CONSTRAINT appello_pkey PRIMARY KEY (corso_laurea, codice, data);
|
||||
|
||||
|
||||
--
|
||||
-- Name: corso_laurea corso_laurea_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.corso_laurea
|
||||
ADD CONSTRAINT corso_laurea_pkey PRIMARY KEY (nome);
|
||||
|
||||
|
||||
--
|
||||
-- Name: docente docente_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.docente
|
||||
ADD CONSTRAINT docente_pkey PRIMARY KEY (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: insegnamento insegnamento_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.insegnamento
|
||||
ADD CONSTRAINT insegnamento_pkey PRIMARY KEY (corso_laurea, codice);
|
||||
|
||||
|
||||
--
|
||||
-- Name: propedeuticita propedeuticita_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.propedeuticita
|
||||
ADD CONSTRAINT propedeuticita_pkey PRIMARY KEY (codice_is, corso_is, corso_has, codice_has);
|
||||
|
||||
|
||||
--
|
||||
-- Name: segretario segretario_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.segretario
|
||||
ADD CONSTRAINT segretario_pkey PRIMARY KEY (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: segreteria segreteria_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.segreteria
|
||||
ADD CONSTRAINT segreteria_pkey PRIMARY KEY (indirizzo);
|
||||
|
||||
|
||||
--
|
||||
-- Name: sostiene sostiene_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.sostiene
|
||||
ADD CONSTRAINT sostiene_pkey PRIMARY KEY (studente, corso_laurea, codice, data);
|
||||
|
||||
|
||||
--
|
||||
-- Name: str_sostiene str_sostiene_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.str_sostiene
|
||||
ADD CONSTRAINT str_sostiene_pkey PRIMARY KEY (studente, corso_laurea, codice, data);
|
||||
|
||||
|
||||
--
|
||||
-- Name: str_studente str_studente_email_key; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.str_studente
|
||||
ADD CONSTRAINT str_studente_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: str_studente str_studente_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.str_studente
|
||||
ADD CONSTRAINT str_studente_pkey PRIMARY KEY (matricola);
|
||||
|
||||
|
||||
--
|
||||
-- Name: studente studente_email_key; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.studente
|
||||
ADD CONSTRAINT studente_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: studente studente_pkey; Type: CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.studente
|
||||
ADD CONSTRAINT studente_pkey PRIMARY KEY (matricola);
|
||||
|
||||
|
||||
--
|
||||
-- Name: insegnamento gestione_anni_insegnamento; Type: TRIGGER; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TRIGGER gestione_anni_insegnamento BEFORE INSERT ON uni.insegnamento FOR EACH ROW EXECUTE PROCEDURE uni.anno_insegnamento();
|
||||
|
||||
|
||||
--
|
||||
-- Name: appello gestione_appelli_esami; Type: TRIGGER; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TRIGGER gestione_appelli_esami BEFORE INSERT ON uni.appello FOR EACH ROW EXECUTE PROCEDURE uni.appelli_esami();
|
||||
|
||||
|
||||
--
|
||||
-- Name: sostiene gestione_iscrizione_esami; Type: TRIGGER; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TRIGGER gestione_iscrizione_esami BEFORE INSERT ON uni.sostiene FOR EACH ROW EXECUTE PROCEDURE uni.iscrizione_esami();
|
||||
|
||||
|
||||
--
|
||||
-- Name: insegnamento gestione_numero_insegnamenti_docente; Type: TRIGGER; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TRIGGER gestione_numero_insegnamenti_docente AFTER INSERT ON uni.insegnamento FOR EACH ROW EXECUTE PROCEDURE uni.numero_insegnamenti_docente();
|
||||
|
||||
|
||||
--
|
||||
-- Name: studente storico_studente_carriera; Type: TRIGGER; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
CREATE TRIGGER storico_studente_carriera BEFORE DELETE ON uni.studente FOR EACH ROW EXECUTE PROCEDURE uni.str_studente_carriera();
|
||||
|
||||
|
||||
--
|
||||
-- Name: appello appello_insegnamento_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.appello
|
||||
ADD CONSTRAINT appello_insegnamento_fkey FOREIGN KEY (corso_laurea, codice) REFERENCES uni.insegnamento(corso_laurea, codice);
|
||||
|
||||
|
||||
--
|
||||
-- Name: corso_laurea corso_laurea_segreteria_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.corso_laurea
|
||||
ADD CONSTRAINT corso_laurea_segreteria_fkey FOREIGN KEY (segreteria) REFERENCES uni.segreteria(indirizzo) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: propedeuticita has_prop_insegnamento_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.propedeuticita
|
||||
ADD CONSTRAINT has_prop_insegnamento_fkey FOREIGN KEY (corso_has, codice_has) REFERENCES uni.insegnamento(corso_laurea, codice);
|
||||
|
||||
|
||||
--
|
||||
-- Name: insegnamento insegnamento_responsabile_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.insegnamento
|
||||
ADD CONSTRAINT insegnamento_responsabile_fkey FOREIGN KEY (responsabile) REFERENCES uni.docente(email) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: propedeuticita is_prop_insegnamento_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.propedeuticita
|
||||
ADD CONSTRAINT is_prop_insegnamento_fkey FOREIGN KEY (corso_is, codice_is) REFERENCES uni.insegnamento(corso_laurea, codice);
|
||||
|
||||
|
||||
--
|
||||
-- Name: segretario segretario_segreteria_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.segretario
|
||||
ADD CONSTRAINT segretario_segreteria_fkey FOREIGN KEY (segreteria) REFERENCES uni.segreteria(indirizzo) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: sostiene sostiene_appello_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.sostiene
|
||||
ADD CONSTRAINT sostiene_appello_fkey FOREIGN KEY (corso_laurea, codice, data) REFERENCES uni.appello(corso_laurea, codice, data);
|
||||
|
||||
|
||||
--
|
||||
-- Name: studente studente_corso_laurea_fkey; Type: FK CONSTRAINT; Schema: uni; Owner: bitnami
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY uni.studente
|
||||
ADD CONSTRAINT studente_corso_laurea_fkey FOREIGN KEY (corso_laurea) REFERENCES uni.corso_laurea(nome) ON UPDATE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,583 @@
|
||||
-- Downloaded from: https://github.com/heydabop/rustyz/blob/f26ef98d6439f7cc046125ab75ecd2bc7b0ae3b7/schema.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 12.4 (Debian 12.4-3)
|
||||
-- Dumped by pg_dump version 12.4 (Debian 12.4-3)
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: online_status; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE public.online_status AS ENUM (
|
||||
'dnd',
|
||||
'idle',
|
||||
'invisible',
|
||||
'offline',
|
||||
'online'
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment_carrier; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE public.shipment_carrier AS ENUM (
|
||||
'fedex',
|
||||
'ups',
|
||||
'usps'
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment_tracking_status; Type: TYPE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TYPE public.shipment_tracking_status AS ENUM (
|
||||
'unknown',
|
||||
'pre_transit',
|
||||
'transit',
|
||||
'delivered',
|
||||
'returned',
|
||||
'failure'
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: row_update_date(); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.row_update_date() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
begin
|
||||
new.update_date = now();
|
||||
return new;
|
||||
end;
|
||||
$$;
|
||||
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: bot_start; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.bot_start (
|
||||
id integer NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
update_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
clean_shutdown boolean
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: bot_start_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.bot_start_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: bot_start_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.bot_start_id_seq OWNED BY public.bot_start.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: command; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.command (
|
||||
id integer NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
channel_id bigint NOT NULL,
|
||||
guild_id bigint,
|
||||
name character varying(32) NOT NULL,
|
||||
options jsonb
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: command_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.command_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: command_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.command_id_seq OWNED BY public.command.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: message; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.message (
|
||||
id bigint NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
discord_id numeric NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
channel_id bigint NOT NULL,
|
||||
guild_id bigint,
|
||||
content text,
|
||||
update_date timestamp with time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: message_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.message_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: message_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.message_id_seq OWNED BY public.message.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: playtime_button; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.playtime_button (
|
||||
id integer NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
user_ids bigint[] NOT NULL,
|
||||
username character varying(32),
|
||||
start_date timestamp with time zone,
|
||||
end_date timestamp with time zone NOT NULL,
|
||||
start_offset integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: playtime_button_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.playtime_button_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: playtime_button_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.playtime_button_id_seq OWNED BY public.playtime_button.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.shipment (
|
||||
id integer NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
update_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
carrier public.shipment_carrier NOT NULL,
|
||||
tracking_number character varying(100) NOT NULL,
|
||||
author_id bigint NOT NULL,
|
||||
channel_id bigint NOT NULL,
|
||||
status public.shipment_tracking_status NOT NULL,
|
||||
comment character varying(50)
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.shipment_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.shipment_id_seq OWNED BY public.shipment.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_karma; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_karma (
|
||||
guild_id bigint NOT NULL,
|
||||
user_id bigint NOT NULL,
|
||||
karma integer NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_presence; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.user_presence (
|
||||
id bigint NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
user_id bigint NOT NULL,
|
||||
status public.online_status NOT NULL,
|
||||
game_name character varying(512)
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_presence_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.user_presence_id_seq
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_presence_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.user_presence_id_seq OWNED BY public.user_presence.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.vote (
|
||||
id integer NOT NULL,
|
||||
create_date timestamp with time zone DEFAULT now() NOT NULL,
|
||||
guild_id bigint NOT NULL,
|
||||
voter_id bigint NOT NULL,
|
||||
votee_id bigint NOT NULL,
|
||||
is_upvote boolean NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote_id_seq; Type: SEQUENCE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.vote_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.vote_id_seq OWNED BY public.vote.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: bot_start id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.bot_start ALTER COLUMN id SET DEFAULT nextval('public.bot_start_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: command id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.command ALTER COLUMN id SET DEFAULT nextval('public.command_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: message id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.message ALTER COLUMN id SET DEFAULT nextval('public.message_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: playtime_button id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.playtime_button ALTER COLUMN id SET DEFAULT nextval('public.playtime_button_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.shipment ALTER COLUMN id SET DEFAULT nextval('public.shipment_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_presence id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_presence ALTER COLUMN id SET DEFAULT nextval('public.user_presence_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote id; Type: DEFAULT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.vote ALTER COLUMN id SET DEFAULT nextval('public.vote_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: bot_start bot_start_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.bot_start
|
||||
ADD CONSTRAINT bot_start_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: command command_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.command
|
||||
ADD CONSTRAINT command_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: message message_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.message
|
||||
ADD CONSTRAINT message_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment shipment_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.shipment
|
||||
ADD CONSTRAINT shipment_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment shipment_uk_carrier_number; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.shipment
|
||||
ADD CONSTRAINT shipment_uk_carrier_number UNIQUE (carrier, tracking_number);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_karma user_karma_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_karma
|
||||
ADD CONSTRAINT user_karma_pkey PRIMARY KEY (guild_id, user_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_presence user_presence_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.user_presence
|
||||
ADD CONSTRAINT user_presence_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote vote_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.vote
|
||||
ADD CONSTRAINT vote_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: user_karma_guild_id_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX user_karma_guild_id_idx ON public.user_karma USING btree (guild_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: vote_voter_id_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX vote_voter_id_idx ON public.vote USING btree (voter_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: bot_start bot_start_row_update_date; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER bot_start_row_update_date BEFORE UPDATE ON public.bot_start FOR EACH ROW EXECUTE FUNCTION public.row_update_date();
|
||||
|
||||
|
||||
--
|
||||
-- Name: message message_row_update_date; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER message_row_update_date BEFORE UPDATE ON public.message FOR EACH ROW EXECUTE FUNCTION public.row_update_date();
|
||||
|
||||
|
||||
--
|
||||
-- Name: shipment shipment_row_update_date; Type: TRIGGER; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TRIGGER shipment_row_update_date BEFORE UPDATE ON public.shipment FOR EACH ROW EXECUTE FUNCTION public.row_update_date();
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE bot_start; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,UPDATE ON TABLE public.bot_start TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE bot_start_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.bot_start_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE command; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT ON TABLE public.command TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE command_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.command_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE message; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,DELETE,UPDATE ON TABLE public.message TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE message_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.message_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE playtime_button; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,UPDATE ON TABLE public.playtime_button TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE playtime_button_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.playtime_button_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE shipment; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,UPDATE ON TABLE public.shipment TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE shipment_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.shipment_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE user_karma; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,UPDATE ON TABLE public.user_karma TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE user_presence; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT ON TABLE public.user_presence TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE user_presence_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.user_presence_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: TABLE vote; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT SELECT,INSERT,UPDATE ON TABLE public.vote TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- Name: SEQUENCE vote_id_seq; Type: ACL; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
GRANT USAGE ON SEQUENCE public.vote_id_seq TO rustyz;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,645 @@
|
||||
-- Downloaded from: https://github.com/ii-habibi/Dental-Clinic/blob/214da734250e375ec01f7aef4fca580af37db0bb/Database_Schema.sql
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 17.2
|
||||
-- Dumped by pg_dump version 17.2
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET transaction_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
--
|
||||
-- Name: update_timestamp(); Type: FUNCTION; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.update_timestamp() RETURNS trigger
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$;
|
||||
|
||||
|
||||
ALTER FUNCTION public.update_timestamp() OWNER TO postgres;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: admins; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.admins (
|
||||
id integer NOT NULL,
|
||||
username character varying(50) NOT NULL,
|
||||
password character varying(255) NOT NULL,
|
||||
is_super_admin boolean DEFAULT false,
|
||||
name character varying(20) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.admins OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: admins_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.admins_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.admins_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: admins_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.admins_id_seq OWNED BY public.admins.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointment; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.appointment (
|
||||
appointment_id integer NOT NULL,
|
||||
patient_id integer,
|
||||
doctor_id integer,
|
||||
appointment_date date,
|
||||
appointment_time time without time zone,
|
||||
treatment_type character varying(255),
|
||||
status character varying(50),
|
||||
visit_type character varying(50),
|
||||
notes text,
|
||||
payment_status character varying(50),
|
||||
amount numeric(10,2),
|
||||
payment_date timestamp without time zone,
|
||||
payment_message text
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.appointment OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: appointment_appointment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.appointment_appointment_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.appointment_appointment_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: appointment_appointment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.appointment_appointment_id_seq OWNED BY public.appointment.appointment_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.audit_logs (
|
||||
id integer NOT NULL,
|
||||
admin_id integer NOT NULL,
|
||||
appointment_id integer,
|
||||
action_type character varying(50),
|
||||
old_value jsonb,
|
||||
new_value jsonb,
|
||||
created_at timestamp without time zone DEFAULT now(),
|
||||
expense_id integer,
|
||||
income_id integer
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.audit_logs OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: audit_logs_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.audit_logs_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.audit_logs_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: audit_logs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.audit_logs_id_seq OWNED BY public.audit_logs.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: blog; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.blog (
|
||||
blog_id integer NOT NULL,
|
||||
title character varying(255) NOT NULL,
|
||||
content text,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
author character varying(255)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.blog OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: blog_blog_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.blog_blog_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.blog_blog_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: blog_blog_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.blog_blog_id_seq OWNED BY public.blog.blog_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: doctors; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.doctors (
|
||||
id integer NOT NULL,
|
||||
name character varying(100) NOT NULL,
|
||||
qualification character varying(255) NOT NULL,
|
||||
expertise text NOT NULL,
|
||||
photo character varying(255),
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.doctors OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: doctors_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.doctors_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.doctors_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: doctors_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.doctors_id_seq OWNED BY public.doctors.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: expenses; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.expenses (
|
||||
id integer NOT NULL,
|
||||
doctor_id integer,
|
||||
amount numeric(10,2) NOT NULL,
|
||||
type character varying(50) NOT NULL,
|
||||
description text,
|
||||
date timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.expenses OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: expenses_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.expenses_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.expenses_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: expenses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.expenses_id_seq OWNED BY public.expenses.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: incomes; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.incomes (
|
||||
id integer NOT NULL,
|
||||
description character varying(255) NOT NULL,
|
||||
amount numeric(10,2) NOT NULL,
|
||||
date date NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.incomes OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: incomes_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.incomes_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.incomes_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: incomes_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.incomes_id_seq OWNED BY public.incomes.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: patients; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.patients (
|
||||
patient_id integer NOT NULL,
|
||||
name character varying(255),
|
||||
email character varying(255),
|
||||
phone character varying(20),
|
||||
age integer,
|
||||
gender character varying(10),
|
||||
address character varying(200)
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.patients OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: patients_patient_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.patients_patient_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.patients_patient_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: patients_patient_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.patients_patient_id_seq OWNED BY public.patients.patient_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: services; Type: TABLE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TABLE public.services (
|
||||
service_id integer NOT NULL,
|
||||
name character varying(100) NOT NULL,
|
||||
description text,
|
||||
price numeric(10,2) NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.services OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: services_service_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.services_service_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.services_service_id_seq OWNER TO postgres;
|
||||
|
||||
--
|
||||
-- Name: services_service_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.services_service_id_seq OWNED BY public.services.service_id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins ALTER COLUMN id SET DEFAULT nextval('public.admins_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointment appointment_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointment ALTER COLUMN appointment_id SET DEFAULT nextval('public.appointment_appointment_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs ALTER COLUMN id SET DEFAULT nextval('public.audit_logs_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: blog blog_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.blog ALTER COLUMN blog_id SET DEFAULT nextval('public.blog_blog_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: doctors id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.doctors ALTER COLUMN id SET DEFAULT nextval('public.doctors_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: expenses id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.expenses ALTER COLUMN id SET DEFAULT nextval('public.expenses_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: incomes id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.incomes ALTER COLUMN id SET DEFAULT nextval('public.incomes_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: patients patient_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.patients ALTER COLUMN patient_id SET DEFAULT nextval('public.patients_patient_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: services service_id; Type: DEFAULT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.services ALTER COLUMN service_id SET DEFAULT nextval('public.services_service_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins admins_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins
|
||||
ADD CONSTRAINT admins_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: admins admins_username_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.admins
|
||||
ADD CONSTRAINT admins_username_key UNIQUE (username);
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointment appointment_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointment
|
||||
ADD CONSTRAINT appointment_pkey PRIMARY KEY (appointment_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs audit_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs
|
||||
ADD CONSTRAINT audit_logs_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: blog blog_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.blog
|
||||
ADD CONSTRAINT blog_pkey PRIMARY KEY (blog_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: doctors doctors_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.doctors
|
||||
ADD CONSTRAINT doctors_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: expenses expenses_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.expenses
|
||||
ADD CONSTRAINT expenses_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: incomes incomes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.incomes
|
||||
ADD CONSTRAINT incomes_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: patients patients_email_key; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.patients
|
||||
ADD CONSTRAINT patients_email_key UNIQUE (email);
|
||||
|
||||
|
||||
--
|
||||
-- Name: patients patients_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.patients
|
||||
ADD CONSTRAINT patients_pkey PRIMARY KEY (patient_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: services services_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.services
|
||||
ADD CONSTRAINT services_pkey PRIMARY KEY (service_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_appointment_payment_date; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_appointment_payment_date ON public.appointment USING btree (payment_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_expenses_date; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_expenses_date ON public.expenses USING btree (date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_expenses_type; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_expenses_type ON public.expenses USING btree (type);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_incomes_amount; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_incomes_amount ON public.incomes USING btree (amount);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_incomes_date; Type: INDEX; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE INDEX idx_incomes_date ON public.incomes USING btree (date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: incomes set_timestamp_incomes; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER set_timestamp_incomes BEFORE UPDATE ON public.incomes FOR EACH ROW EXECUTE FUNCTION public.update_timestamp();
|
||||
|
||||
|
||||
--
|
||||
-- Name: services set_timestamp_services; Type: TRIGGER; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
CREATE TRIGGER set_timestamp_services BEFORE UPDATE ON public.services FOR EACH ROW EXECUTE FUNCTION public.update_timestamp();
|
||||
|
||||
|
||||
--
|
||||
-- Name: appointment appointment_patient_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.appointment
|
||||
ADD CONSTRAINT appointment_patient_id_fkey FOREIGN KEY (patient_id) REFERENCES public.patients(patient_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs audit_logs_admin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs
|
||||
ADD CONSTRAINT audit_logs_admin_id_fkey FOREIGN KEY (admin_id) REFERENCES public.admins(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs audit_logs_appointment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs
|
||||
ADD CONSTRAINT audit_logs_appointment_id_fkey FOREIGN KEY (appointment_id) REFERENCES public.appointment(appointment_id) ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs audit_logs_expense_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs
|
||||
ADD CONSTRAINT audit_logs_expense_id_fkey FOREIGN KEY (expense_id) REFERENCES public.expenses(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: audit_logs audit_logs_income_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.audit_logs
|
||||
ADD CONSTRAINT audit_logs_income_id_fkey FOREIGN KEY (income_id) REFERENCES public.incomes(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: expenses expenses_doctor_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.expenses
|
||||
ADD CONSTRAINT expenses_doctor_id_fkey FOREIGN KEY (doctor_id) REFERENCES public.doctors(id) ON DELETE SET NULL;
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user