Skip to content

kdave007/dbf_meta_to_postgresql_tool

Repository files navigation

DBF Metadata to PostgreSQL

A simple tool to read DBF files, extract their metadata, and prepare for PostgreSQL table creation.

Features

  • Simple Configuration: JSON-based configuration file
  • DBF Metadata Extraction: Read field names, types, lengths, and other metadata
  • Clean Output: Formatted console output and optional JSON export
  • Easy to Use: Simple class-based design

Installation

  1. Install required dependencies:
pip install -r requirements.txt

Configuration

Update the config.json file with your settings:

{
  "dbf_file_path": "path/to/your/file.dbf",
  "output": {
    "show_metadata": true,
    "show_field_details": true,
    "export_to_json": false,
    "json_output_path": "metadata_output.json"
  },
  "database": {
    "host": "localhost",
    "port": 5432,
    "database": "your_database",
    "username": "your_username",
    "password": "your_password"
  }
}

Usage

Basic Usage

from src.dbf_reader import DBFReader

# Initialize reader with config file
reader = DBFReader("config.json")

# Read DBF metadata
metadata = reader.read_dbf_metadata()

# Print formatted metadata
reader.print_metadata()

# Get specific information
table_name = reader.get_table_name()
field_names = reader.get_field_names()
fields_info = reader.get_fields_info()

Using with a specific DBF file

# Read a specific DBF file (overrides config)
metadata = reader.read_dbf_metadata("path/to/specific/file.dbf")

Export metadata to JSON

# Export metadata to JSON file
json_file = reader.export_metadata_to_json("output.json")

Testing

Run the test script to verify everything works:

cd src/test
python test_dbf_reader.py

Project Structure

DBF_meta_to_postgresql/
├── config.json              # Configuration file
├── requirements.txt          # Python dependencies
├── README.md                # This file
└── src/
    ├── dbf_reader.py        # Main DBF reader class
    └── test/
        └── test_dbf_reader.py  # Test script

Output Example

============================================================
DBF FILE METADATA
============================================================
File Name: example.dbf
File Path: path/to/example.dbf
File Size: 1,234 bytes
Record Count: 100
Field Count: 5
Last Modified: 2024-01-15

============================================================
FIELD INFORMATION
============================================================
Field Name      Type         Length   Decimals  Description
------------------------------------------------------------
ID              N            10       0         Numeric
NAME            C            50       0         Character/Text
DATE_CREATED    D            8        0         Date
AMOUNT          N            12       2         Numeric
ACTIVE          L            1        0         Logical/Boolean

Next Steps

This is the first step in the DBF to PostgreSQL migration process. Future enhancements will include:

  1. SQL table creation query generation
  2. Data type mapping from DBF to PostgreSQL
  3. Data migration functionality
  4. Batch processing capabilities

Requirements

  • Python 3.7+
  • dbf library for DBF file reading
  • psycopg2-binary for PostgreSQL connectivity (future use)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages