Skip to content

Fix migrate_to_sql.py (syntax error + bad import), add missing schema.sql, .gitignore, requirements.txt#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-syntax-error-migrate-to-sql
Draft

Fix migrate_to_sql.py (syntax error + bad import), add missing schema.sql, .gitignore, requirements.txt#1
Copilot wants to merge 2 commits intomainfrom
copilot/fix-syntax-error-migrate-to-sql

Conversation

Copy link

Copilot AI commented Mar 11, 2026

migrate_to_sql.py was unparseable and could never execute. db/schema.sql didn't exist despite being opened at startup. networkx was undeclared and __pycache__/.db files were tracked by git.

Fixes in migrate_to_sql.py

  • Syntax error (line 61): stray nhm token inside subscript — imp["line" nhm]imp["line"]
  • Bad import (line 5): decompose_source doesn't exist in ast_decomposer.py — replaced with ASTDecomposer class and updated call site to ASTDecomposer(source).get_full_decomposition()
  • Wrong dict key (lines 71, 76): _decompose_function returns self_explanatory_name, not name — would have raised KeyError at runtime after the above fixes landed
# Before
from src.ast_decomposer import decompose_source
...
logic = decompose_source(source)
...
(module_id, imp["module"], json.dumps(imp["names"]), imp["line" nhm]))
...
method["name"], ...
func["name"], ...

# After
from src.ast_decomposer import ASTDecomposer
...
decomposer = ASTDecomposer(source)
logic = decomposer.get_full_decomposition()
...
(module_id, imp["module"], json.dumps(imp["names"]), imp["line"]))
...
method["self_explanatory_name"], ...
func["self_explanatory_name"], ...

New files

  • db/schema.sql — normalized schema (modules, imports, classes, functions, constants, dependency_map) that migrate_to_sql.py and dependency_resolver.py both query against; was referenced on line 18 but never existed
  • requirements.txt — declares networkx>=3.0
  • .gitignore — excludes __pycache__/, *.db, .nuanced/, standard Python build artifacts
Original prompt

Context

This project was working and then broke during recent changes. The owner needs the codebase back to a fully functional state. DO NOT delete any files. DO NOT redesign the architecture. Fix only what is broken. Match the owner's existing code style — human-readable, component-based, composed.

What Is Broken (fix ONLY these)

1. migrate_to_sql.py — Two bugs preventing execution

Bug A — Line 61: Syntax error

# BROKEN (line 61):
(module_id, imp["module"], json.dumps(imp["names"]), imp["line" nhm]))
# FIX:
(module_id, imp["module"], json.dumps(imp["names"]), imp["line"]))

nhm is a stray token that makes the file unparseable. Just remove it.

Bug B — Line 5: Import references a function that doesn't exist

# BROKEN:
from src.ast_decomposer import decompose_source
# FIX — use the ASTDecomposer class that actually exists in src/ast_decomposer.py:
from src.ast_decomposer import ASTDecomposer

Then update migrate() around line 43 to use the class:

# BROKEN:
logic = decompose_source(source)
# FIX:
decomposer = ASTDecomposer(source)
logic = decomposer.get_full_decomposition()

2. db/schema.sql — Missing file that migrate_to_sql.py tries to read

migrate_to_sql.py line 18 does with open(SCHEMA_PATH, "r") as f: conn.executescript(f.read()) where SCHEMA_PATH = "db/schema.sql". That file doesn't exist. Create it with the normalized schema that migrate_to_sql.py and src/dependency_resolver.py both expect. Looking at what those files query, the schema must be:

-- db/schema.sql
-- Normalized schema for the LogicAIn Codebase-as-Data registry.
-- Used by migrate_to_sql.py for the advanced cross-module pipeline.

CREATE TABLE IF NOT EXISTS modules (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    path TEXT UNIQUE NOT NULL,
    sha256 TEXT,
    last_synced TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS imports (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    module_id INTEGER NOT NULL,
    imported_module TEXT,
    imported_names TEXT,
    line_number INTEGER,
    FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS classes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    module_id INTEGER NOT NULL,
    name TEXT NOT NULL,
    bases TEXT,
    docstring TEXT,
    line_number INTEGER,
    FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS functions (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    module_id INTEGER NOT NULL,
    class_id INTEGER,
    name TEXT NOT NULL,
    arguments TEXT,
    return_type TEXT,
    docstring TEXT,
    logic_calls TEXT,
    line_start INTEGER,
    line_end INTEGER,
    resolved_logic_id INTEGER,
    FOREIGN KEY(module_id) REFERENCES modules(id),
    FOREIGN KEY(class_id) REFERENCES classes(id),
    FOREIGN KEY(resolved_logic_id) REFERENCES functions(id)
);

CREATE TABLE IF NOT EXISTS constants (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    module_id INTEGER NOT NULL,
    name TEXT NOT NULL,
    value TEXT,
    line_number INTEGER,
    FOREIGN KEY(module_id) REFERENCES modules(id)
);

CREATE TABLE IF NOT EXISTS dependency_map (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    source_function_id INTEGER NOT NULL,
    target_function_id INTEGER NOT NULL,
    call_type TEXT DEFAULT 'direct',
    FOREIGN KEY(source_function_id) REFERENCES functions(id),
    FOREIGN KEY(target_function_id) REFERENCES functions(id)
);

3. Add .gitignore (missing — __pycache__/ dirs are committed)

Create .gitignore with standard Python entries:

__pycache__/
*.pyc
*.pyo
*.db
.env
.venv/
*.egg-info/
dist/
build/
.nuanced/

4. Add requirements.txt (missing — networkx dependency undeclared)

Create requirements.txt:

networkx>=3.0

CRITICAL RULES

  • DO NOT delete any existing files — not codegen.py, not dependency_resolver.py, not migrate_to_sql.py, not anything
  • DO NOT modify src/ast_decomposer.py, src/graph_engine.py, sync_codebase.py, logic.py, src/codegen.py, src/dependency_resolver.py, db/pdx_exploration.sql
  • DO NOT modify any test files
  • Only touch: migrate_to_sql.py (fix the two bugs), create db/schema.sql, create .gitignore, create requirements.txt
  • Match the existing code style — clean, readable Python with comments

The following is the prior conversation context from the user's chat exploration (may be truncated):

Assistant: Now let me read the core files to fully understand the project:

Assistant: Now let me look at the remaining source files to get the full picture:

Assistant: Now let me check the remaining key files:

Assistant: OK — I've now read every file in the repo. Here's my honest, thorough assessment.


Understanding LogicAIn — The Full Picture

LogicAIn is a Codebase-as-Data toolkit: it uses Python's ast module to decompose source files into structured relational records (functions, classes, imports, constants), stores them in SQL...

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@JoeyBe1
Copy link
Owner

JoeyBe1 commented Mar 11, 2026

This sees stalled @copilot

…ts.txt

Co-authored-by: JoeyBe1 <165391182+JoeyBe1@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bugs in migrate_to_sql.py for execution issues Fix migrate_to_sql.py (syntax error + bad import), add missing schema.sql, .gitignore, requirements.txt Mar 11, 2026
Copy link
Author

Copilot AI commented Mar 11, 2026

This sees stalled @copilot

Not stalled — all fixes are complete and pushed in commit 609b973. Here's what was done:

  • migrate_to_sql.py: syntax error (imp["line" nhm]) fixed, bad import (decompose_sourceASTDecomposer) fixed, wrong dict key (nameself_explanatory_name) fixed — the file now parses and runs cleanly
  • db/schema.sql: created with the full normalized schema (modules, imports, classes, functions, constants, dependency_map)
  • .gitignore and requirements.txt: created

All 9 existing tests pass. Ready to merge.

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.

2 participants