-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Progress Bar Persistence Read/Write #20787
Changes from all commits
0be298c
d6e12a7
326c555
402913c
513c068
5bf2b49
6d3661f
6699e03
ed35076
055a599
3d3a5bc
4c6701a
1059b86
8d304f4
efca05e
5500bc2
6b7eddd
56436ff
44f6bb6
c25d472
b3a1027
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.db.instance.jobs.migrations; | ||
|
||
import static org.jooq.impl.DSL.constraint; | ||
|
||
import org.flywaydb.core.api.migration.BaseJavaMigration; | ||
import org.flywaydb.core.api.migration.Context; | ||
import org.jooq.DSLContext; | ||
import org.jooq.impl.DSL; | ||
import org.jooq.impl.SQLDataType; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class V0_40_26_001__CorrectStreamStatsTable extends BaseJavaMigration { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(V0_40_26_001__CorrectStreamStatsTable.class); | ||
|
||
@Override | ||
public void migrate(final Context context) throws Exception { | ||
LOGGER.info("Running migration: {}", this.getClass().getSimpleName()); | ||
|
||
// Warning: please do not use any jOOQ generated code to write a migration. | ||
// As database schema changes, the generated jOOQ code can be deprecated. So | ||
// old migration may not compile if there is any generated code. | ||
try (final DSLContext ctx = DSL.using(context.getConnection())) { | ||
// This actually needs to be bigint to match the id column on the attempts table. | ||
String streamStats = "stream_stats"; | ||
ctx.alterTable(streamStats).alter("attempt_id").set(SQLDataType.BIGINT.nullable(false)).execute(); | ||
// Not all streams provide a namespace. | ||
ctx.alterTable(streamStats).alter("stream_namespace").set(SQLDataType.VARCHAR.nullable(true)).execute(); | ||
|
||
// The constraint should also take into account the stream namespace. Drop the constraint and | ||
// recreate it. | ||
ctx.alterTable(streamStats).dropUnique("stream_stats_attempt_id_stream_name_key").execute(); | ||
ctx.alterTable(streamStats).add(constraint("uniq_stream_attempt").unique("attempt_id", "stream_name", "stream_namespace")).execute(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this constraint doesn't behave as you expect it to because of how SQL handles NULL values. last time I looked at this with jooq, I ended up checking this in our application logic because some solutions were postgres specific and I was not able to figure out the joop way of describing it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did check the current constraint separately (manually writing to the database) and it does include the NULL namespace case (i.e. errors out). This makes me think this is a JOOQ thing. I also checked both constraints and in combination with the above, decided this is simpler than adding another constraint that only exists because of JOOQ. |
||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sorted this file and added the estimated fields.