diff --git a/STRUCTURE.md b/STRUCTURE.md index 98372cf..be8da66 100644 --- a/STRUCTURE.md +++ b/STRUCTURE.md @@ -16,7 +16,7 @@ example-name/ ├── README.md # Documentation and usage examples ├── run.py # Main implementation ├── guide.md # (Optional) Additional technical details -└── repo-before/ # (Optional) Sample code for transformation +└── input_repo/ # (Optional) Sample code for transformation ``` ## Code Organization in `run.py` @@ -43,7 +43,7 @@ Your `run.py` should follow this structure, demonstrated well in the `generate_t @codegen.function("your-function-name") def run(codebase: Codebase): """Clear docstring explaining what the function does. - + Include: 1. Purpose of the function 2. Key steps or transformations @@ -128,7 +128,7 @@ def get_function_context(function) -> dict: @codegen.function("generate-training-data") def run(codebase: Codebase): """Generate training data using a node2vec-like approach... - + This codemod: 1. Finds all functions... 2. For each function... diff --git a/examples/flask_to_fastapi_migration/README.md b/examples/flask_to_fastapi_migration/README.md index 3803f56..0b1b41b 100644 --- a/examples/flask_to_fastapi_migration/README.md +++ b/examples/flask_to_fastapi_migration/README.md @@ -63,8 +63,7 @@ The script will process all Python files in the `repo-before` directory and appl ## Understanding the Code - `run.py` - The migration script -- `repo-before/` - Sample Flask application to migrate -- `guide.md` - Additional notes and explanations +- `input_repo/` - Sample Flask application to migrate ## Learn More diff --git a/examples/python2_to_python3/README.md b/examples/python2_to_python3/README.md index f393861..cf342b7 100644 --- a/examples/python2_to_python3/README.md +++ b/examples/python2_to_python3/README.md @@ -83,8 +83,7 @@ The script will process all Python files in the `repo-before` directory and appl ## Understanding the Code - `run.py` - The migration script -- `repo-before/` - Sample Python 2 code to migrate -- `guide.md` - Additional notes and explanations +- `input_repo/` - Sample Python 2 code to migrate ## Learn More diff --git a/examples/sqlalchemy_1.6_to_2.0/README.md b/examples/sqlalchemy_1.6_to_2.0/README.md index da0e1d8..746b064 100644 --- a/examples/sqlalchemy_1.6_to_2.0/README.md +++ b/examples/sqlalchemy_1.6_to_2.0/README.md @@ -60,23 +60,10 @@ The migration script handles four key transformations: addresses: Mapped[List["Address"]] = relationship() ``` -## Running the Example - -```bash -# Install Codegen -pip install codegen - -# Run the migration -python run.py -``` - -The script will process all Python files in the `repo-before` directory and apply the transformations in the correct order. - ## Understanding the Code -- `run.py` - The migration script -- `repo-before/` - Sample SQLAlchemy 1.6 application to migrate -- `guide.md` - Additional notes and explanations +- `input_repo` - Sample SQLAlchemy 1.6 application to migrate +- `output_repo` - Sample SQLAlchemy 2.0 application after migration ## Learn More diff --git a/examples/sqlalchemy_1.6_to_2.0/guide.md b/examples/sqlalchemy_1.6_to_2.0/guide.md deleted file mode 100644 index 9135dac..0000000 --- a/examples/sqlalchemy_1.6_to_2.0/guide.md +++ /dev/null @@ -1,96 +0,0 @@ -# Guide: Migrating from SQLAlchemy 1.6 to 2.0 with Codegen - -This guide walks you through the steps to migrate your codebase from SQLAlchemy 1.6 to 2.0 using Codegen. Follow along to modernize your imports, relationships, and query syntax while ensuring compatibility with SQLAlchemy 2.0. Each step includes a direct link to the appropriate codemod for easy implementation. - ---- - -## 🎉 Overview of Changes - -The migration focuses on these key updates: - -1. **Import Adjustments** - Aligns your code with the updated SQLAlchemy 2.0 module structure. - [Run the Import Codemod](https://www.codegen.sh/search/6506?skillType=codemod) - -2. **Relationship Updates** - Refines relationship definitions by replacing `backref` with `back_populates` for explicitness and better readability. - [Run the Relationship Codemod](https://www.codegen.sh/search/6510?skillType=codemod) - -3. **Query Syntax Modernization** - Updates queries to leverage the latest syntax like `select()` and `where()`, removing deprecated methods. - [Run the Query Syntax Codemod](https://www.codegen.sh/search/6508?skillType=codemod) - -4. **Relationship Lazy Loading** - SQLAlchemy 2.0 introduces a new `lazy` parameter for relationship definitions. Update your relationships to use the new `lazy` parameter for improved performance. - [Run the Relationship Lazy Loading Codemod](https://www.codegen.sh/search/6512?skillType=codemod) - -5. **Type Annotations** - SQLAlchemy 2.0 has improved type annotation support. Update your models to include type hints for better IDE support and runtime type checking. - - - Add type annotations to model attributes and relationships - - Leverage SQLAlchemy's typing module for proper type hints - - Enable better IDE autocompletion and type checking - - [Run the Type Annotations Codemod](https://www.codegen.sh/search/4645?skillType=codemod) - ---- - -## How to Migrate - -### Step 1: Update Imports - -SQLAlchemy 2.0 introduces a refined import structure. Use the import codemod to: - -- Replace wildcard imports (`*`) with explicit imports for better clarity. -- Update `declarative_base` to `DeclarativeBase`. - -👉 [Run the Import Codemod](https://www.codegen.sh/search/6506?skillType=codemod) - ---- - -### Step 2: Refactor Relationships - -In SQLAlchemy 2.0, relationships require more explicit definitions. This includes: - -- Transitioning from `backref` to `back_populates` for consistency. -- Explicitly specifying `back_populates` for all relationship definitions. - -👉 [Run the Relationship Codemod](https://www.codegen.sh/search/6510?skillType=codemod) - ---- - -### Step 3: Modernize Query Syntax - -The query API has been revamped in SQLAlchemy 2.0. Key updates include: - -- Switching to `select()` and `where()` for query construction. -- Replacing any deprecated methods with their modern equivalents. - -👉 [Run the Query Syntax Codemod](https://www.codegen.sh/search/6508?skillType=codemod) - ---- - -### Step 4: Update Relationship Lazy Loading - -SQLAlchemy 2.0 introduces a new `lazy` parameter for relationship definitions. Update your relationships to use the new `lazy` parameter for improved performance. - -👉 [Run the Relationship Lazy Loading Codemod](https://www.codegen.sh/search/6512?skillType=codemod) - ---- - -### Step 5: Add Type Annotations -SQLAlchemy 2.0 has improved type annotation support. Update your models to include type hints for better IDE support and runtime type checking. - -- Add type annotations to model attributes and relationships -- Leverage SQLAlchemy's typing module for proper type hints -- Enable better IDE autocompletion and type checking - -👉 [Run the Type Annotations Codemod](https://www.codegen.sh/search/4645?skillType=codemod) - ---- - -## Need Help? - -If you encounter issues or have specific edge cases not addressed by the codemods, reach out to the Codegen support team or visit the [Codegen Documentation](https://www.codegen.sh/docs) for detailed guidance. - -Start your SQLAlchemy 2.0 migration today and enjoy the benefits of a cleaner, modern codebase! diff --git a/examples/unittest_to_pytest/README.md b/examples/unittest_to_pytest/README.md index 91095ca..ecf4e4a 100644 --- a/examples/unittest_to_pytest/README.md +++ b/examples/unittest_to_pytest/README.md @@ -89,8 +89,7 @@ The script will process all Python test files in the `repo-before` directory and ## Understanding the Code - `run.py` - The migration script -- `repo-before/` - Sample `unittest` test suite to migrate -- `guide.md` - Additional notes and explanations +- `input_repo/` - Sample `unittest` test suite to migrate ## Learn More