Repository: optuna/optuna

Issue:
ImportError: cannot import name 'declarative_base' from 'sqlalchemy.orm' (/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/__init__.py)
### Expected behavior

I got the following error message when using a old vesion of SQLAlchemy (the version is 1.3.8)

```
ImportError: cannot import name 'declarative_base' from 'sqlalchemy.orm' (/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/__init__.py)
```


### Environment

- Optuna version: 3.0.0
- Python version: 3.7.13
- OS: ?
- (Optional) Other libraries and their versions:
I used Google Colab to reproduce the error.
the version of SQLAlchemy is 1.3.8

### Error messages, stack traces, or logs

```shell
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-4-004b4427a179>](https://localhost:8080/#) in <module>
      2 
      3 storage = "sqlite:///example.db"
----> 4 study = optuna.create_study(storage=storage)

19 frames
[/usr/local/lib/python3.7/dist-packages/optuna/_convert_positional_args.py](https://localhost:8080/#) in converter_wrapper(*args, **kwargs)
     59                 kwargs[arg_name] = val
     60 
---> 61             return func(**kwargs)
     62 
     63         return converter_wrapper

[/usr/local/lib/python3.7/dist-packages/optuna/study/study.py](https://localhost:8080/#) in create_study(storage, sampler, pruner, study_name, direction, load_if_exists, directions)
   1145     ]
   1146 
-> 1147     storage = storages.get_storage(storage)
   1148     try:
   1149         study_id = storage.create_new_study(study_name)

[/usr/local/lib/python3.7/dist-packages/optuna/storages/__init__.py](https://localhost:8080/#) in get_storage(storage)
     30             return _CachedStorage(RedisStorage(storage))
     31         else:
---> 32             return _CachedStorage(RDBStorage(storage))
     33     elif isinstance(storage, (RDBStorage, RedisStorage)):
     34         return _CachedStorage(storage)

[/usr/local/lib/python3.7/dist-packages/optuna/storages/_rdb/storage.py](https://localhost:8080/#) in __init__(self, url, engine_kwargs, skip_compatibility_check, heartbeat_interval, grace_period, failed_trial_callback, skip_table_creation)
    221             models.BaseModel.metadata.create_all(self.engine)
    222 
--> 223         self._version_manager = _VersionManager(self.url, self.engine, self.scoped_session)
    224         if not skip_compatibility_check:
    225             self._version_manager.check_table_schema_compatibility()

[/usr/local/lib/python3.7/dist-packages/optuna/storages/_rdb/storage.py](https://localhost:8080/#) in __init__(self, url, engine, scoped_session)
   1083         self.scoped_session = scoped_session
   1084         self._init_version_info_model()
-> 1085         self._init_alembic()
   1086 
   1087     def _init_version_info_model(self) -> None:

[/usr/local/lib/python3.7/dist-packages/optuna/storages/_rdb/storage.py](https://localhost:8080/#) in _init_alembic(self)
   1110 
   1111         if self._is_alembic_supported():
-> 1112             revision = self.get_head_version()
   1113         else:
   1114             # The storage has been created before alembic is introduced.

[/usr/local/lib/python3.7/dist-packages/optuna/storages/_rdb/storage.py](https://localhost:8080/#) in get_head_version(self)
   1166 
   1167         script = self._create_alembic_script()
-> 1168         current_head = script.get_current_head()
   1169         assert current_head is not None
   1170         return current_head

[/usr/local/lib/python3.7/dist-packages/alembic/script/base.py](https://localhost:8080/#) in get_current_head(self)
    380             )
    381         ):
--> 382             return self.revision_map.get_current_head()
    383 
    384     def get_heads(self) -> List[str]:

[/usr/local/lib/python3.7/dist-packages/alembic/script/revision.py](https://localhost:8080/#) in get_current_head(self, branch_label)
    485 
    486         """
--> 487         current_heads: Sequence[str] = self.heads
    488         if branch_label:
    489             current_heads = self.filter_for_lineage(

[/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py](https://localhost:8080/#) in __get__(self, obj, cls)
    853         if obj is None:
    854             return self
--> 855         obj.__dict__[self.__name__] = result = self.fget(obj)
    856         return result
    857 

[/usr/local/lib/python3.7/dist-packages/alembic/script/revision.py](https://localhost:8080/#) in heads(self)
    135 
    136         """
--> 137         self._revision_map
    138         return self.heads
    139 

[/usr/local/lib/python3.7/dist-packages/sqlalchemy/util/langhelpers.py](https://localhost:8080/#) in __get__(self, obj, cls)
    853         if obj is None:
    854             return self
--> 855         obj.__dict__[self.__name__] = result = self.fget(obj)
    856         return result
    857 

[/usr/local/lib/python3.7/dist-packages/alembic/script/revision.py](https://localhost:8080/#) in _revision_map(self)
    189         all_revisions = set()
    190 
--> 191         for revision in self._generator():
    192             all_revisions.add(revision)
    193 

[/usr/local/lib/python3.7/dist-packages/alembic/script/base.py](https://localhost:8080/#) in _load_revisions(self)
    138                     continue
    139                 dupes.add(path)
--> 140                 script = Script._from_filename(self, vers, file_)
    141                 if script is None:
    142                     continue

[/usr/local/lib/python3.7/dist-packages/alembic/script/base.py](https://localhost:8080/#) in _from_filename(cls, scriptdir, dir_, filename)
   1011                 return None
   1012 
-> 1013         module = util.load_python_file(dir_, filename)
   1014 
   1015         if not hasattr(module, "revision"):

[/usr/local/lib/python3.7/dist-packages/alembic/util/pyfiles.py](https://localhost:8080/#) 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)

[/usr/local/lib/python3.7/dist-packages/alembic/util/pyfiles.py](https://localhost:8080/#) 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

/usr/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

[/usr/local/lib/python3.7/dist-packages/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py](https://localhost:8080/#) in <module>
     15 from sqlalchemy import ForeignKey
     16 from sqlalchemy import Integer
---> 17 from sqlalchemy.orm import declarative_base
     18 from sqlalchemy.orm import Session
     19 

ImportError: cannot import name 'declarative_base' from 'sqlalchemy.orm' (/usr/local/lib/python3.7/dist-packages/sqlalchemy/orm/__init__.py)
```
```


### Steps to reproduce

1. create new Google Colab notebook
2. install packages optuna and sqlalchemy like this:
```
!pip install -U optuna==v3.0.0 SQLAlchemy==1.3.8
```
4. create study with sqlite
```python
import optuna

storage = "sqlite:///example.db"
study = optuna.create_study(storage=storage)
```


### Additional context (optional)

_No response_


Discussion:

Resolving patch:
diff --git a/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py b/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py
--- a/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py
+++ b/optuna/storages/_rdb/alembic/versions/v3.0.0.b.py
@@ -14,7 +14,7 @@
 from sqlalchemy import Float
 from sqlalchemy import ForeignKey
 from sqlalchemy import Integer
-from sqlalchemy.orm import declarative_base
+from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.orm import Session
 
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -29,7 +29,7 @@ def get_long_description() -> str:
 def get_install_requires() -> List[str]:
 
     requirements = [
-        "alembic",
+        "alembic>=1.5.0",
         "cliff",
         "cmaes>=0.8.2",
         "colorlog",
@@ -37,7 +37,7 @@ def get_install_requires() -> List[str]:
         "packaging>=20.0",
         # TODO(kstoneriv3): remove this after deprecation of Python 3.6
         "scipy!=1.4.0" if sys.version[:3] == "3.6" else "scipy>=1.7.0",
-        "sqlalchemy>=1.1.0",
+        "sqlalchemy>=1.3.0",
         "tqdm",
         "typing_extensions>=3.10.0.0",
         "PyYAML",  # Only used in `optuna/cli.py`.


Test patch: