Skip to content

Commit 638fd86

Browse files
committed
Create a postgres DB instance with 'the_simpsons' schema.
1 parent 32ce4d0 commit 638fd86

File tree

4 files changed

+104
-0
lines changed

4 files changed

+104
-0
lines changed

debezium/docker-compose.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
services:
3+
# https://hub.docker.com/_/postgres
4+
db:
5+
container_name: db
6+
image: postgres
7+
restart: always
8+
environment:
9+
- POSTGRES_USER=postgres
10+
- POSTGRES_PASSWORD=postgres
11+
ports:
12+
- '5432:5432'
13+
volumes:
14+
- ./postgres_data:/var/lib/postgresql/data
15+
- ./src/main/resources/dml/schema.sql:/docker-entrypoint-initdb.d/schema.sql
16+
command: [ "postgres", "-c", "wal_level=logical" ]
17+
adminer:
18+
image: adminer
19+
restart: always
20+
ports:
21+
- 8081:8081

debezium/pom.xml

+53
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
<maven.compiler.target>21</maven.compiler.target>
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<spring-boot.version>2.7.18</spring-boot.version>
21+
<postgresql.version>42.2.5</postgresql.version>
22+
<debezium.version>2.7.2.Final</debezium.version>
2123
</properties>
2224

2325
<dependencies>
@@ -50,6 +52,24 @@
5052
<version>1.18.30</version>
5153
<scope>provided</scope>
5254
</dependency>
55+
56+
<dependency>
57+
<groupId>org.postgresql</groupId>
58+
<artifactId>postgresql</artifactId>
59+
<version>${postgresql.version}</version>
60+
</dependency>
61+
62+
<!-- Debezium -->
63+
<dependency>
64+
<groupId>io.debezium</groupId>
65+
<artifactId>debezium-embedded</artifactId>
66+
<version>${debezium.version}</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>io.debezium</groupId>
70+
<artifactId>debezium-connector-postgres</artifactId>
71+
<version>${debezium.version}</version>
72+
</dependency>
5373
</dependencies>
5474

5575
<dependencyManagement>
@@ -86,6 +106,39 @@
86106
</execution>
87107
</executions>
88108
</plugin>
109+
110+
<plugin>
111+
<groupId>io.fabric8</groupId>
112+
<artifactId>docker-maven-plugin</artifactId>
113+
<version>0.45.0</version>
114+
<configuration></configuration>
115+
<executions>
116+
<execution>
117+
<id>start</id>
118+
<!--<phase>pre-integration-test</phase>-->
119+
<phase>generate-test-resources</phase>
120+
<goals>
121+
<goal>build</goal>
122+
<goal>start</goal>
123+
</goals>
124+
</execution>
125+
<execution>
126+
<id>stop</id>
127+
<phase>post-integration-test</phase>
128+
<goals>
129+
<goal>stop</goal>
130+
</goals>
131+
</execution>
132+
<execution>
133+
<id>stop-pre</id>
134+
<phase>clean</phase>
135+
<goals>
136+
<goal>stop</goal>
137+
</goals>
138+
</execution>
139+
</executions>
140+
</plugin>
141+
89142
</plugins>
90143
</build>
91144

debezium/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
https://www.baeldung.com/debezium-intro
66
https://ishansoninitj.medium.com/change-data-capture-cdc-using-debezium-in-a-springboot-application-97ddde8b991a
77
https://gist.github.com/tzolov/c3bfa56237f0d4ceb53a93b6c80436e3
8+
https://github.com/tzolov/cdc-debezium/tree/master
89

910
### Avro
1011

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
------/* schema.*/
2+
--- https://github.com/hackmods/The-the_simpsons-SQL
3+
CREATE SCHEMA the_simpsons;
4+
------/* character.*/
5+
CREATE TABLE IF NOT EXISTS the_simpsons.character (
6+
id SERIAL NOT NULL PRIMARY KEY,
7+
name VARCHAR NOT NULL,
8+
surname VARCHAR NOT NULL,
9+
update_ts TIMESTAMP DEFAULT current_timestamp NOT NULL
10+
);
11+
------/*Insertion des données dans la table character.*/
12+
INSERT INTO the_simpsons.character (nom, pays) VALUES
13+
('Homer','Simpson'),
14+
('Bart','Simpson'),
15+
('Lisa','Simpson');
16+
------/*Trigger pour maj de la date "update_ts"*/
17+
CREATE OR REPLACE FUNCTION maj_date()
18+
RETURNS TRIGGER AS $$
19+
BEGIN
20+
NEW.update_ts := NOW();
21+
RETURN NEW;
22+
END;
23+
$$ LANGUAGE plpgsql;
24+
CREATE TRIGGER maj_date_trigger
25+
BEFORE INSERT OR UPDATE ON the_simpsons.character
26+
FOR EACH ROW
27+
EXECUTE FUNCTION maj_date();
28+
------/*Tres utile pour obtenir des details dans la section before de la donnée*/
29+
ALTER TABLE the_simpsons.character REPLICA IDENTITY FULL;

0 commit comments

Comments
 (0)