Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Jun 26, 2023
1 parent 046c91c commit bc62843
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -404,16 +404,22 @@ type Connection
registry - but that means it was created by Enso as a hidden table.
generate_dry_run_table_name : Text -> Text
generate_dry_run_table_name self table_name =
max_length = (self.max_table_name_length.if_nothing 60) - 1
go ix =
prefix = "enso-dry-run-" + if ix == 0 then "" else ix.to_text + "-"
max_length = (self.max_table_name_length.if_nothing 60) - 1
name = prefix + table_name.take (max_length - prefix.length)
## The dry run name is ok if it is already registered (that means it
may exist in the Database, but it was created by other dry runs
and is safe to overwrite) or if it does not exist in the database.
name_ok = (self.hidden_table_registry.is_registered name) || (self.table_exists name . not)
if name_ok then name else
@Tail_Call go (ix + 1)
## This check ensures that if all possible names are taken, the
method will not loop forever but report an error. It should never
occur in practice - it would mean that the Database contains
unimaginable amounts of dry run tables or has impractically small
table name length limit.
if prefix.length > max_length then Error.throw (Illegal_State.Error "Reached the table name length limit ("+max_length.to_text+") while trying to find a unused table name. It seems that all possible names are already taken. The Database may need to be cleaned up for dry run to work." else
name = (prefix + table_name) . take max_length
## The dry run name is ok if it is already registered (that means it
may exist in the Database, but it was created by other dry runs
and is safe to overwrite) or if it does not exist in the database.
name_ok = (self.hidden_table_registry.is_registered name) || (self.table_exists name . not)
if name_ok then name else
@Tail_Call go (ix + 1)
go 0

## PRIVATE
Expand Down

0 comments on commit bc62843

Please sign in to comment.