Skip to content

Commit 6514f75

Browse files
committed
move drop scheme before create
1 parent 425a78b commit 6514f75

File tree

15 files changed

+32
-47
lines changed

15 files changed

+32
-47
lines changed

dev-1/lesson-3.1/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void main(String[] args) {
1919
var schemaYdbRepository = new SchemaYdbRepository(retryCtx);
2020
var issueYdbRepository = new IssueYdbRepository(retryCtx);
2121

22+
schemaYdbRepository.dropSchema();
2223
schemaYdbRepository.createSchema();
2324

2425
issueYdbRepository.addIssue("Ticket 1");
@@ -28,8 +29,6 @@ public static void main(String[] args) {
2829
for (var ticket : issueYdbRepository.findAll()) {
2930
System.out.println("Ticket: {id: " + ticket.id() + ", title: " + ticket.title() + ", timestamp: " + ticket.now() + "}");
3031
}
31-
32-
schemaYdbRepository.dropSchema();
3332
}
3433
}
3534
}

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void main(String[] args) {
1919
var schemaYdbRepository = new SchemaYdbRepository(retryCtx);
2020
var issueYdbRepository = new IssueYdbRepository(retryCtx);
2121

22+
schemaYdbRepository.dropSchema();
2223
schemaYdbRepository.createSchema();
2324

2425
issueYdbRepository.addIssue("Ticket 1", "Author 1");
@@ -54,8 +55,6 @@ public static void main(String[] args) {
5455
for (var ticket : issueYdbRepository.findAll()) {
5556
printIssue(ticket);
5657
}
57-
58-
schemaYdbRepository.dropSchema();
5958
}
6059
}
6160
}

dev-1/lesson-4.1/java/src/main/java/tech/ydb/app/SchemaYdbRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public void dropSchema() {
4747
retryCtx.supplyResult(
4848
session -> session.createQuery(
4949
"""
50-
DROP TABLE issues;
51-
DROP TABLE links;
50+
DROP TABLE IF EXISTS issues;
51+
DROP TABLE IF EXISTS links;
5252
""", TxMode.NONE
5353
).execute()
5454
).join().getStatus().expectSuccess("Can't drop table issues");

dev-1/lesson-5.1/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static void main(String[] args) {
1919
var schemaYdbRepository = new SchemaYdbRepository(retryCtx);
2020
var issueYdbRepository = new IssueYdbRepository(retryCtx);
2121

22+
schemaYdbRepository.dropSchema();
2223
schemaYdbRepository.createSchema();
2324

2425
issueYdbRepository.addIssue("Ticket 1", "Author 1");
@@ -34,8 +35,6 @@ public static void main(String[] args) {
3435

3536
System.out.println("Find by index `authorIndex`: ");
3637
printIssue(issueYdbRepository.findByAuthor("Author 2"));
37-
38-
schemaYdbRepository.dropSchema();
3938
}
4039
}
4140
}

dev-1/lesson-5.1/java/src/main/java/tech/ydb/app/SchemaYdbRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public void dropSchema() {
5555
retryCtx.supplyResult(
5656
session -> session.createQuery(
5757
"""
58-
DROP TABLE issues;
59-
DROP TABLE links;
58+
DROP TABLE IF EXISTS issues;
59+
DROP TABLE IF EXISTS links;
6060
""", TxMode.NONE
6161
).execute()
6262
).join().getStatus().expectSuccess("Can't drop table issues");

dev-1/lesson-6.1/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static void main(String[] args) throws InterruptedException {
2121
var schemaYdbRepository = new SchemaYdbRepository(retryCtx);
2222
var issueYdbRepository = new IssueYdbRepository(retryCtx);
2323

24+
schemaYdbRepository.dropSchema();
2425
schemaYdbRepository.createSchema();
2526

2627
issueYdbRepository.addIssue("Ticket 1", "Author 1");
@@ -58,8 +59,6 @@ public static void main(String[] args) throws InterruptedException {
5859
for (var ticket : issueYdbRepository.findAll()) {
5960
printIssue(ticket);
6061
}
61-
62-
schemaYdbRepository.dropSchema();
6362
}
6463
}
6564

dev-1/lesson-6.1/java/src/main/java/tech/ydb/app/SchemaYdbRepository.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public void dropSchema() {
7272
retryCtx.supplyResult(
7373
session -> session.createQuery(
7474
"""
75-
DROP TABLE issues;
76-
DROP TABLE links;
77-
DROP TOPIC task_status;
75+
DROP TABLE IF EXISTS issues;
76+
DROP TABLE IF EXISTS links;
77+
DROP TOPIC IF EXISTS task_status;
7878
""", TxMode.NONE
7979
).execute()
8080
).join().getStatus().expectSuccess("Can't drop table issues");

dev-1/lesson-6.2/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public static void main(String[] args) throws IOException, InterruptedException
4040

4141
var retryCtx = SessionRetryContext.create(queryClient).build();
4242

43+
dropSchema(retryCtx);
4344
createSchema(retryCtx);
4445

4546
var writer = topicClient.createSyncWriter(
@@ -121,8 +122,6 @@ public static void main(String[] args) throws IOException, InterruptedException
121122
printTableFile(retryCtx);
122123

123124
readerJob.join();
124-
125-
dropSchema(retryCtx);
126125
}
127126
}
128127

@@ -254,10 +253,10 @@ CREATE TOPIC file_topic (
254253

255254
private static void dropSchema(SessionRetryContext retryCtx) {
256255
executeSchema(retryCtx, """
257-
DROP TABLE file;
258-
DROP TABLE file_progress;
259-
DROP TABLE write_file_progress;
260-
DROP TOPIC file_topic;
256+
DROP TABLE IF EXISTS file;
257+
DROP TABLE IF EXISTS file_progress;
258+
DROP TABLE IF EXISTS write_file_progress;
259+
DROP TOPIC IF EXISTS file_topic;
261260
""");
262261
}
263262

dev-1/lesson-6.3/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public static void main(String[] args) throws IOException, InterruptedException
4444

4545
var retryCtx = SessionRetryContext.create(queryClient).build();
4646

47+
dropSchema(retryCtx);
4748
createSchema(retryCtx);
4849

4950
var reader = topicClient.createSyncReader(
@@ -83,12 +84,12 @@ public static void main(String[] args) throws IOException, InterruptedException
8384
var origLineNumber = new AtomicLong(1);
8485

8586
lines.forEach(line -> {
86-
if (origLineNumber.getAndIncrement() < lineNumber.get()) {
87+
if (origLineNumber.getAndIncrement() < lineNumber.get()) {
8788
return;
8889
}
8990

90-
var lineNumberCur = lineNumber.getAndIncrement();
91-
retryCtx.supplyStatus(
91+
var lineNumberCur = lineNumber.getAndIncrement();
92+
retryCtx.supplyStatus(
9293
session -> {
9394
var transaction = session.beginTransaction(TxMode.SERIALIZABLE_RW).join().getValue();
9495
var writer = topicClient.createSyncWriter(
@@ -138,8 +139,6 @@ public static void main(String[] args) throws IOException, InterruptedException
138139
readerJob.join();
139140

140141
printTableFile(retryCtx);
141-
142-
dropSchema(retryCtx);
143142
}
144143
}
145144

@@ -242,9 +241,9 @@ CREATE TOPIC file_topic (
242241

243242
private static void dropSchema(SessionRetryContext retryCtx) {
244243
executeSchema(retryCtx, """
245-
DROP TABLE file;
246-
DROP TABLE write_file_progress;
247-
DROP TOPIC file_topic;
244+
DROP TABLE IF EXISTS file;
245+
DROP TABLE IF EXISTS write_file_progress;
246+
DROP TOPIC IF EXISTS file_topic;
248247
""");
249248
}
250249

dev-1/lesson-7.1/java/src/main/java/tech/ydb/app/Application.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static void main(String[] args) throws InterruptedException {
2222
var schemaYdbRepository = new SchemaYdbRepository(retryCtx);
2323
var issueYdbRepository = new IssueYdbRepository(retryCtx);
2424

25+
schemaYdbRepository.dropSchema();
2526
schemaYdbRepository.createSchema();
2627

2728
var first = issueYdbRepository.addIssue("Ticket 1", "Author 1");
@@ -40,8 +41,6 @@ public static void main(String[] args) throws InterruptedException {
4041
for (var ticket : issueYdbRepository.findAll()) {
4142
printIssue(ticket);
4243
}
43-
44-
schemaYdbRepository.dropSchema();
4544
}
4645
}
4746

0 commit comments

Comments
 (0)