54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""
|
|
Check if provider_validations table exists and create if not.
|
|
"""
|
|
import asyncio
|
|
from sqlalchemy import text
|
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
from app.core.config import settings
|
|
|
|
|
|
async def main():
|
|
engine = create_async_engine(str(settings.SQLALCHEMY_DATABASE_URI))
|
|
|
|
async with engine.connect() as conn:
|
|
# Check if table exists
|
|
result = await conn.execute(
|
|
text("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'marketplace' AND table_name = 'provider_validations')")
|
|
)
|
|
exists = result.scalar()
|
|
print(f"provider_validations table exists: {exists}")
|
|
|
|
if not exists:
|
|
# Create the table
|
|
await conn.execute(text("""
|
|
CREATE TABLE IF NOT EXISTS marketplace.provider_validations (
|
|
id SERIAL PRIMARY KEY,
|
|
provider_id INTEGER NOT NULL REFERENCES marketplace.service_providers(id) ON DELETE CASCADE,
|
|
voter_user_id INTEGER NOT NULL REFERENCES identity.users(id) ON DELETE CASCADE,
|
|
validation_type VARCHAR(20) NOT NULL DEFAULT 'approve',
|
|
weight INTEGER NOT NULL DEFAULT 1,
|
|
metadata JSONB DEFAULT '{}'::jsonb,
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
UNIQUE(voter_user_id, provider_id)
|
|
)
|
|
"""))
|
|
await conn.commit()
|
|
print("Created provider_validations table")
|
|
|
|
# Check columns
|
|
result = await conn.execute(text("""
|
|
SELECT column_name, data_type, is_nullable
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'marketplace' AND table_name = 'provider_validations'
|
|
ORDER BY ordinal_position
|
|
"""))
|
|
print("\nColumns:")
|
|
for row in result:
|
|
print(f" {row.column_name}: {row.data_type} (nullable: {row.is_nullable})")
|
|
|
|
await engine.dispose()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|