Skip to content

feat: add create_table parameter to control automatic table creation#10

Merged
nomeguy merged 3 commits intomasterfrom
copilot/prevent-automatic-table-creation
Nov 16, 2025
Merged

feat: add create_table parameter to control automatic table creation#10
nomeguy merged 3 commits intomasterfrom
copilot/prevent-automatic-table-creation

Conversation

Copy link
Contributor

Copilot AI commented Nov 16, 2025

The Adapter class automatically creates database tables via metadata.create_all() during initialization, which is problematic when tables are managed externally (e.g., by migration systems) or when the adapter should act purely as an intermediary.

Changes

sqlalchemy_adapter/adapter.py:

  • Added create_table=True parameter to Adapter.__init__() (defaults to True for backward compatibility)
  • Conditionally call metadata.create_all() only when create_table=True

tests/test_adapter.py:

  • Added 4 tests covering default behavior, explicit True/False, custom table names, and custom db_class

README.md:

  • Documented new parameter with usage examples and use cases

Usage

from sqlalchemy import create_engine
import sqlalchemy_adapter

# Prevent automatic table creation
engine = create_engine('postgresql://...')
adapter = sqlalchemy_adapter.Adapter(engine, create_table=False)

# Tables must be created separately (e.g., via migrations)
# Adapter functions purely as an intermediary

Existing code continues to work unchanged as the parameter defaults to True.

Original prompt

This section details on the original issue you should resolve

<issue_title>Prevent sqlalchemy_adapter.Adapter from automatically creating tables</issue_title>
<issue_description>Is there a way to use it only as an intermediary without creating any tables?

I am using sqlalchemy_adapter.Adapter, and I have observed that it automatically creates the corresponding tables in the database during initialization.

My goal is to use the adapter strictly as an intermediary between SQLAlchemy and the system that consumes it, without having it manage or create any tables.

I would like to know:

Whether there is an option or parameter to disable automatic table creation.

Whether there is a recommended way to configure the adapter so that it does not call metadata.create_all() or create any database structures.

Any guidance or references would be appreciated.

engine = get_engine_postgres()

adapter_rbac = sqlalchemy_adapter.Adapter(engine)
# adapter_rebac = sqlalchemy_adapter.Adapter(engine, db_class=CasbinRuleReBAC)
# adapter_rebac = sqlalchemy_adapter.Adapter(engine, table_name=CasbinRuleReBAC.__tablename__)
Lib\site-packages\sqlalchemy_adapter\adapter.py:33: SAWarning: This declarative base already contains a class with the same class name and module name as sqlalchemy_adapter.adapter.CasbinRule, and will be replaced in the string-lookup table.        
  class CasbinRule(Base):
--- All Policies (p) ---
['alice', '/api/v1/items', 'GET']
--- All Role Assignments (g) ---
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@nomeguy nomeguy marked this pull request as ready for review November 16, 2025 15:48
Copilot AI and others added 2 commits November 16, 2025 15:52
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Prevent sqlalchemy_adapter.Adapter from creating tables Add create_table parameter to control automatic table creation Nov 16, 2025
Copilot AI requested a review from nomeguy November 16, 2025 15:58
@nomeguy nomeguy changed the title Add create_table parameter to control automatic table creation feat: add create_table parameter to control automatic table creation Nov 16, 2025
@nomeguy nomeguy merged commit d0ac58d into master Nov 16, 2025
13 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 16, 2025
# [1.8.0](v1.7.0...v1.8.0) (2025-11-16)

### Features

* add `create_table` parameter to control automatic table creation ([#10](#10)) ([0ac6def](0ac6def))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent sqlalchemy_adapter.Adapter from automatically creating tables

2 participants