We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bug: alembic downgrade from 6828cc5b1a4f to 5b43800443d1 fails.
### Meltano Version

downgrading from 2+ to 1.76

### Python Version

3.7

### Bug scope

Other

### Operating System

Windows, but this probably isn't OS specific.

### Description

Relates to #6870. Ran `meltano repl` (as advised by @DouweM) then:

```python
from alembic import command
from alembic.config import Config
from meltano.migrations import MIGRATION_DIR
from alembic.runtime.migration import MigrationContext
from alembic.script import ScriptDirectory

engine, session = project_engine(project, default=True)
conn = engine.connect()
cfg = Config()
cfg.attributes["connection"] = conn
cfg.set_main_option("script_location", str(MIGRATION_DIR))
script = ScriptDirectory.from_config(cfg)
context = MigrationContext.configure(conn)
command.downgrade(cfg, "d135f52a6f49")
```

Tracelog:

```
2022-10-11T11:24:19.745585Z [info     ] Context impl PostgresqlImpl.
2022-10-11T11:24:19.747541Z [info     ] Will assume transactional DDL.
2022-10-11T11:24:19.853452Z [info     ] Running downgrade 6828cc5b1a4f -> f4c225a9492f, Create dedicated state table
2022-10-11T11:24:19.898474Z [info     ] Running downgrade f4c225a9492f -> 5b43800443d1, Create dedicated job_state table ---------------------------------------------------------------------------
UndefinedTable                            Traceback (most recent call last)
~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)
   1900                     self.dialect.do_execute(
-> 1901                         cursor, statement, parameters, context
   1902                     )

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\default.py in do_execute(self, cursor, statement, parameters, context)
    735     def do_execute(self, cursor, statement, parameters, context=None):
--> 736         cursor.execute(statement, parameters)
    737

UndefinedTable: table "state" does not exist


The above exception was the direct cause of the following exception:

ProgrammingError                          Traceback (most recent call last)
<ipython-input-14-8baf3a7dd97e> in <module>
----> 1 command.downgrade(cfg, "d135f52a6f49")

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\command.py in downgrade(config, revision, sql, tag)
    366         tag=tag,
    367     ):
--> 368         script.run_env()
    369
    370

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\script\base.py in run_env(self)
    567
    568         """
--> 569         util.load_python_file(self.dir, "env.py")
    570
    571     @property

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\util\pyfiles.py in load_python_file(dir_, filename)
     92     if ext == ".py":
     93         if os.path.exists(path):
---> 94             module = load_module_py(module_id, path)
     95         else:
     96             pyc_path = pyc_file_from_path(path)

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\util\pyfiles.py in load_module_py(module_id, path)
    108     assert spec
    109     module = importlib.util.module_from_spec(spec)
--> 110     spec.loader.exec_module(module)  # type: ignore
    111     return module

~\AppData\Local\Programs\Python\Python37\lib\importlib\_bootstrap_external.py in exec_module(self, module)

~\AppData\Local\Programs\Python\Python37\lib\importlib\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\meltano\migrations\env.py in <module>
     58     run_migrations_offline()
     59 else:
---> 60     run_migrations_online()

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\meltano\migrations\env.py in run_migrations_online()
     35     connection = config.attributes.get("connection")
     36     if connection:
---> 37         _run_migrations_online(connection)
     38         return
     39

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\meltano\migrations\env.py in _run_migrations_online(connection)
     52
     53     with context.begin_transaction():
---> 54         context.run_migrations()
     55
     56

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\context.py in run_migrations(*args, **kw)

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\runtime\environment.py in run_migrations(self, **kw)
    851         assert self._migration_context is not None
    852         with Operations.context(self._migration_context):
--> 853             self.get_context().run_migrations(**kw)
    854
    855     def execute(self, sql, execution_options=None):

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\runtime\migration.py in run_migrations(self, **kw)
    621                         "-- Running %s" % (step.short_log,)
    622                     )
--> 623                 step.migration_fn(**kw)
    624
    625                 # previously, we wouldn't stamp per migration

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\meltano\migrations\versions\f4c225a9492f_create_dedicated_job_state_table.py in downgrade()
     25     # Remove job_state table
     26     # Job run history is still maintained, so no need to copy
---> 27     op.drop_table("state")

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\op.py in drop_table(*args, **kw)

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\operations\base.py in drop_table(self, table_name, schema, **kw)

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\operations\ops.py in drop_table(cls, operations, table_name, schema, **kw)
   1347         """
   1348         op = cls(table_name, schema=schema, table_kw=kw)
-> 1349         operations.invoke(op)
   1350
   1351

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\operations\base.py in invoke(self, operation)
    397             operation, self.migration_context.impl.__dialect__
    398         )
--> 399         return fn(self, operation)
    400
    401     def f(self, name: str) -> "conv":

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\operations\toimpl.py in drop_table(operations, operation)
     78 def drop_table(operations: "Operations", operation: "ops.DropTableOp") -> None:
     79     operations.impl.drop_table(
---> 80         operation.to_table(operations.migration_context)
     81     )
     82

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\ddl\impl.py in drop_table(self, table)
    375             table, self.connection, checkfirst=False, _ddl_runner=self
    376         )
--> 377         self._exec(schema.DropTable(table))
    378         table.dispatch.after_drop(
    379             table, self.connection, checkfirst=False, _ddl_runner=self

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\alembic\ddl\impl.py in _exec(self, construct, execution_options, multiparams, params)
    193                 multiparams += (params,)
    194
--> 195             return conn.execute(construct, multiparams)
    196
    197     def execute(

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in execute(self, statement, *multiparams, **params)
   1378             )
   1379         else:
-> 1380             return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
   1381
   1382     def _execute_function(self, func, multiparams, params, execution_options):

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\sql\ddl.py in _execute_on_connection(self, connection, multiparams, params, execution_options)
     79     ):
     80         return connection._execute_ddl(
---> 81             self, multiparams, params, execution_options
     82         )
     83

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in _execute_ddl(self, ddl, multiparams, params, execution_options)
   1476             None,
   1477             execution_options,
-> 1478             compiled,
   1479         )
   1480         if self._has_events or self.engine._has_events:

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)
   1942         except BaseException as e:
   1943             self._handle_dbapi_exception(
-> 1944                 e, statement, parameters, cursor, context
   1945             )
   1946

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
   2123             elif should_wrap:
   2124                 util.raise_(
-> 2125                     sqlalchemy_exception, with_traceback=exc_info[2], from_=e
   2126                 )
   2127             else:

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\util\compat.py in raise_(***failed resolving arguments***)
    206
    207         try:
--> 208             raise exception
    209         finally:
    210             # credit to

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)
   1899                 if not evt_handled:
   1900                     self.dialect.do_execute(
-> 1901                         cursor, statement, parameters, context
   1902                     )
   1903

~\.virtualenvs\meltano-9aGVMBGe\lib\site-packages\sqlalchemy\engine\default.py in do_execute(self, cursor, statement, parameters, context)
    734
    735     def do_execute(self, cursor, statement, parameters, context=None):
--> 736         cursor.execute(statement, parameters)
    737
    738     def do_execute_no_params(self, cursor, statement, context=None):

ProgrammingError: (psycopg2.errors.UndefinedTable) table "state" does not exist
```

# Diagnosis
- Downgrade path in first migration drops table `state`: https://github.com/meltano/meltano/blob/v2.7.2/src/meltano/migrations/versions/6828cc5b1a4f_create_dedicated_state_table.py#L367
- Downgrade path in second migration also drops table `state`: https://github.com/meltano/meltano/blob/v2.7.2/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py#L27

The second step fails because `state` is already dropped.

# Suggested Fix

Remove the `f4c225a9492f` migration. It does nothing during upgrade, and only causes problems on downgrade.

### Code

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py`
Content:
```
1 """Create dedicated job_state table
2 
3 Revision ID: f4c225a9492f
4 Revises: 5b43800443d1
5 Create Date: 2022-09-02 09:44:05.581824
6 
7 """
8 from __future__ import annotations
9 
10 from alembic import op
11 
12 # revision identifiers, used by Alembic.
13 revision = "f4c225a9492f"
14 down_revision = "5b43800443d1"
15 branch_labels = None
16 depends_on = None
17 
18 
19 def upgrade():
20     # Create state table
21     pass
22 
23 
24 def downgrade():
25     # Remove job_state table
26     # Job run history is still maintained, so no need to copy
27     op.drop_table("state")
28
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py b/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py
--- a/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py
+++ b/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py
@@ -1,4 +1,7 @@
-"""Create dedicated job_state table
+"""THIS IS A NO-OP.
+
+IT EXISTS ONLY TO PREVENT USERS WHO APPLIED THIS MIGRATION
+FROM ENDING UP WITH AN ORPHANED alembic_version IN THEIR DB.
 
 Revision ID: f4c225a9492f
 Revises: 5b43800443d1
@@ -17,11 +20,8 @@
 
 
 def upgrade():
-    # Create state table
     pass
 
 
 def downgrade():
-    # Remove job_state table
-    # Job run history is still maintained, so no need to copy
-    op.drop_table("state")
+    pass

{"golden_diff": "diff --git a/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py b/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py\n--- a/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py\n+++ b/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py\n@@ -1,4 +1,7 @@\n-\"\"\"Create dedicated job_state table\n+\"\"\"THIS IS A NO-OP.\n+\n+IT EXISTS ONLY TO PREVENT USERS WHO APPLIED THIS MIGRATION\n+FROM ENDING UP WITH AN ORPHANED alembic_version IN THEIR DB.\n \n Revision ID: f4c225a9492f\n Revises: 5b43800443d1\n@@ -17,11 +20,8 @@\n \n \n def upgrade():\n-    # Create state table\n     pass\n \n \n def downgrade():\n-    # Remove job_state table\n-    # Job run history is still maintained, so no need to copy\n-    op.drop_table(\"state\")\n+    pass\n", "issue": "bug: alembic downgrade from 6828cc5b1a4f to 5b43800443d1 fails.\n### Meltano Version\n\ndowngrading from 2+ to 1.76\n\n### Python Version\n\n3.7\n\n### Bug scope\n\nOther\n\n### Operating System\n\nWindows, but this probably isn't OS specific.\n\n### Description\n\nRelates to #6870. Ran `meltano repl` (as advised by @DouweM) then:\r\n\r\n```python\r\nfrom alembic import command\r\nfrom alembic.config import Config\r\nfrom meltano.migrations import MIGRATION_DIR\r\nfrom alembic.runtime.migration import MigrationContext\r\nfrom alembic.script import ScriptDirectory\r\n\r\nengine, session = project_engine(project, default=True)\r\nconn = engine.connect()\r\ncfg = Config()\r\ncfg.attributes[\"connection\"] = conn\r\ncfg.set_main_option(\"script_location\", str(MIGRATION_DIR))\r\nscript = ScriptDirectory.from_config(cfg)\r\ncontext = MigrationContext.configure(conn)\r\ncommand.downgrade(cfg, \"d135f52a6f49\")\r\n```\r\n\r\nTracelog:\r\n\r\n```\r\n2022-10-11T11:24:19.745585Z [info     ] Context impl PostgresqlImpl.\r\n2022-10-11T11:24:19.747541Z [info     ] Will assume transactional DDL.\r\n2022-10-11T11:24:19.853452Z [info     ] Running downgrade 6828cc5b1a4f -> f4c225a9492f, Create dedicated state table\r\n2022-10-11T11:24:19.898474Z [info     ] Running downgrade f4c225a9492f -> 5b43800443d1, Create dedicated job_state table ---------------------------------------------------------------------------\r\nUndefinedTable                            Traceback (most recent call last)\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)\r\n   1900                     self.dialect.do_execute(\r\n-> 1901                         cursor, statement, parameters, context\r\n   1902                     )\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\default.py in do_execute(self, cursor, statement, parameters, context)\r\n    735     def do_execute(self, cursor, statement, parameters, context=None):\r\n--> 736         cursor.execute(statement, parameters)\r\n    737\r\n\r\nUndefinedTable: table \"state\" does not exist\r\n\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nProgrammingError                          Traceback (most recent call last)\r\n<ipython-input-14-8baf3a7dd97e> in <module>\r\n----> 1 command.downgrade(cfg, \"d135f52a6f49\")\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\command.py in downgrade(config, revision, sql, tag)\r\n    366         tag=tag,\r\n    367     ):\r\n--> 368         script.run_env()\r\n    369\r\n    370\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\script\\base.py in run_env(self)\r\n    567\r\n    568         \"\"\"\r\n--> 569         util.load_python_file(self.dir, \"env.py\")\r\n    570\r\n    571     @property\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\util\\pyfiles.py in load_python_file(dir_, filename)\r\n     92     if ext == \".py\":\r\n     93         if os.path.exists(path):\r\n---> 94             module = load_module_py(module_id, path)\r\n     95         else:\r\n     96             pyc_path = pyc_file_from_path(path)\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\util\\pyfiles.py in load_module_py(module_id, path)\r\n    108     assert spec\r\n    109     module = importlib.util.module_from_spec(spec)\r\n--> 110     spec.loader.exec_module(module)  # type: ignore\r\n    111     return module\r\n\r\n~\\AppData\\Local\\Programs\\Python\\Python37\\lib\\importlib\\_bootstrap_external.py in exec_module(self, module)\r\n\r\n~\\AppData\\Local\\Programs\\Python\\Python37\\lib\\importlib\\_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\meltano\\migrations\\env.py in <module>\r\n     58     run_migrations_offline()\r\n     59 else:\r\n---> 60     run_migrations_online()\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\meltano\\migrations\\env.py in run_migrations_online()\r\n     35     connection = config.attributes.get(\"connection\")\r\n     36     if connection:\r\n---> 37         _run_migrations_online(connection)\r\n     38         return\r\n     39\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\meltano\\migrations\\env.py in _run_migrations_online(connection)\r\n     52\r\n     53     with context.begin_transaction():\r\n---> 54         context.run_migrations()\r\n     55\r\n     56\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\context.py in run_migrations(*args, **kw)\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\runtime\\environment.py in run_migrations(self, **kw)\r\n    851         assert self._migration_context is not None\r\n    852         with Operations.context(self._migration_context):\r\n--> 853             self.get_context().run_migrations(**kw)\r\n    854\r\n    855     def execute(self, sql, execution_options=None):\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\runtime\\migration.py in run_migrations(self, **kw)\r\n    621                         \"-- Running %s\" % (step.short_log,)\r\n    622                     )\r\n--> 623                 step.migration_fn(**kw)\r\n    624\r\n    625                 # previously, we wouldn't stamp per migration\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\meltano\\migrations\\versions\\f4c225a9492f_create_dedicated_job_state_table.py in downgrade()\r\n     25     # Remove job_state table\r\n     26     # Job run history is still maintained, so no need to copy\r\n---> 27     op.drop_table(\"state\")\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\op.py in drop_table(*args, **kw)\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\operations\\base.py in drop_table(self, table_name, schema, **kw)\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\operations\\ops.py in drop_table(cls, operations, table_name, schema, **kw)\r\n   1347         \"\"\"\r\n   1348         op = cls(table_name, schema=schema, table_kw=kw)\r\n-> 1349         operations.invoke(op)\r\n   1350\r\n   1351\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\operations\\base.py in invoke(self, operation)\r\n    397             operation, self.migration_context.impl.__dialect__\r\n    398         )\r\n--> 399         return fn(self, operation)\r\n    400\r\n    401     def f(self, name: str) -> \"conv\":\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\operations\\toimpl.py in drop_table(operations, operation)\r\n     78 def drop_table(operations: \"Operations\", operation: \"ops.DropTableOp\") -> None:\r\n     79     operations.impl.drop_table(\r\n---> 80         operation.to_table(operations.migration_context)\r\n     81     )\r\n     82\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\ddl\\impl.py in drop_table(self, table)\r\n    375             table, self.connection, checkfirst=False, _ddl_runner=self\r\n    376         )\r\n--> 377         self._exec(schema.DropTable(table))\r\n    378         table.dispatch.after_drop(\r\n    379             table, self.connection, checkfirst=False, _ddl_runner=self\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\alembic\\ddl\\impl.py in _exec(self, construct, execution_options, multiparams, params)\r\n    193                 multiparams += (params,)\r\n    194\r\n--> 195             return conn.execute(construct, multiparams)\r\n    196\r\n    197     def execute(\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in execute(self, statement, *multiparams, **params)\r\n   1378             )\r\n   1379         else:\r\n-> 1380             return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)\r\n   1381\r\n   1382     def _execute_function(self, func, multiparams, params, execution_options):\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\sql\\ddl.py in _execute_on_connection(self, connection, multiparams, params, execution_options)\r\n     79     ):\r\n     80         return connection._execute_ddl(\r\n---> 81             self, multiparams, params, execution_options\r\n     82         )\r\n     83\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in _execute_ddl(self, ddl, multiparams, params, execution_options)\r\n   1476             None,\r\n   1477             execution_options,\r\n-> 1478             compiled,\r\n   1479         )\r\n   1480         if self._has_events or self.engine._has_events:\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)\r\n   1942         except BaseException as e:\r\n   1943             self._handle_dbapi_exception(\r\n-> 1944                 e, statement, parameters, cursor, context\r\n   1945             )\r\n   1946\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)\r\n   2123             elif should_wrap:\r\n   2124                 util.raise_(\r\n-> 2125                     sqlalchemy_exception, with_traceback=exc_info[2], from_=e\r\n   2126                 )\r\n   2127             else:\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\util\\compat.py in raise_(***failed resolving arguments***)\r\n    206\r\n    207         try:\r\n--> 208             raise exception\r\n    209         finally:\r\n    210             # credit to\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\base.py in _execute_context(self, dialect, constructor, statement, parameters, execution_options, *args, **kw)\r\n   1899                 if not evt_handled:\r\n   1900                     self.dialect.do_execute(\r\n-> 1901                         cursor, statement, parameters, context\r\n   1902                     )\r\n   1903\r\n\r\n~\\.virtualenvs\\meltano-9aGVMBGe\\lib\\site-packages\\sqlalchemy\\engine\\default.py in do_execute(self, cursor, statement, parameters, context)\r\n    734\r\n    735     def do_execute(self, cursor, statement, parameters, context=None):\r\n--> 736         cursor.execute(statement, parameters)\r\n    737\r\n    738     def do_execute_no_params(self, cursor, statement, context=None):\r\n\r\nProgrammingError: (psycopg2.errors.UndefinedTable) table \"state\" does not exist\r\n```\r\n\r\n# Diagnosis\r\n- Downgrade path in first migration drops table `state`: https://github.com/meltano/meltano/blob/v2.7.2/src/meltano/migrations/versions/6828cc5b1a4f_create_dedicated_state_table.py#L367\r\n- Downgrade path in second migration also drops table `state`: https://github.com/meltano/meltano/blob/v2.7.2/src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py#L27\r\n\r\nThe second step fails because `state` is already dropped.\r\n\r\n# Suggested Fix\r\n\r\nRemove the `f4c225a9492f` migration. It does nothing during upgrade, and only causes problems on downgrade.\n\n### Code\n\n_No response_\n", "before_files": [{"content": "\"\"\"Create dedicated job_state table\n\nRevision ID: f4c225a9492f\nRevises: 5b43800443d1\nCreate Date: 2022-09-02 09:44:05.581824\n\n\"\"\"\nfrom __future__ import annotations\n\nfrom alembic import op\n\n# revision identifiers, used by Alembic.\nrevision = \"f4c225a9492f\"\ndown_revision = \"5b43800443d1\"\nbranch_labels = None\ndepends_on = None\n\n\ndef upgrade():\n    # Create state table\n    pass\n\n\ndef downgrade():\n    # Remove job_state table\n    # Job run history is still maintained, so no need to copy\n    op.drop_table(\"state\")\n", "path": "src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py"}], "after_files": [{"content": "\"\"\"THIS IS A NO-OP.\n\nIT EXISTS ONLY TO PREVENT USERS WHO APPLIED THIS MIGRATION\nFROM ENDING UP WITH AN ORPHANED alembic_version IN THEIR DB.\n\nRevision ID: f4c225a9492f\nRevises: 5b43800443d1\nCreate Date: 2022-09-02 09:44:05.581824\n\n\"\"\"\nfrom __future__ import annotations\n\nfrom alembic import op\n\n# revision identifiers, used by Alembic.\nrevision = \"f4c225a9492f\"\ndown_revision = \"5b43800443d1\"\nbranch_labels = None\ndepends_on = None\n\n\ndef upgrade():\n    pass\n\n\ndef downgrade():\n    pass\n", "path": "src/meltano/migrations/versions/f4c225a9492f_create_dedicated_job_state_table.py"}]}