What is SQL to Hasura Metadata Generator?
Hasura is a GraphQL engine that instantly provides a GraphQL API over your PostgreSQL database without writing resolvers. It uses metadata configuration files to define which tables are exposed, how relationships are traversed, and what permissions each role has. This converter takes your SQL CREATE TABLE statements and generates a complete Hasura v3 metadata JSON configuration, including table column definitions, primary and unique key constraints, object and array relationships derived from foreign keys, and role-based CRUD permissions for user and anonymous roles.
How to Use
- Paste your SQL CREATE TABLE statements with REFERENCES constraints into the input area
- Click "Generate" to produce the Hasura v3 metadata JSON configuration
- Review the generated table definitions, relationships, and permissions in the output panel
- Customize the permissions for your security requirements — the generated permissions are a starting point
- Apply the metadata using hasura metadata apply or the Hasura Console API
Why Use This Tool?
Tips & Best Practices
- Review and tighten the generated permissions before deploying — the default permissions are intentionally permissive for development
- The anonymous role automatically excludes columns containing "email" or "password" in their name for basic privacy protection
- Add custom check constraints to permissions for row-level security, such as filtering by user_id from session variables
- Use hasura metadata apply to apply the generated configuration, or import it through the Hasura Console
Frequently Asked Questions
What SQL data types are supported for Hasura type mapping?
The tool supports common PostgreSQL types: SERIAL/BIGSERIAL/INTEGER/BIGINT map to integer, VARCHAR/CHAR/TEXT map to text, BOOLEAN maps to boolean, TIMESTAMP/DATE/TIME map to timestamp, NUMERIC/DECIMAL/REAL/DOUBLE/FLOAT map to numeric, UUID maps to uuid, JSON/JSONB map to json. Unsupported types default to text mapping.
When should I avoid using Hasura?
Hasura is designed for PostgreSQL and works best when your API closely mirrors your database schema. Avoid it when you need a custom GraphQL schema that differs significantly from your tables, when you use a database other than PostgreSQL, or when you need complex business logic in your resolvers that cannot be expressed through permissions and computed fields.
How are foreign key relationships handled?
Foreign key REFERENCES are automatically detected and converted into two types of relationships: object relationships on the referencing table (e.g., post.author pointing to User) and array relationships on the referenced table (e.g., user.posts pointing to [Post]). This enables GraphQL clients to traverse relationships without manual configuration.
What permissions are generated?
The tool generates basic permissions for "user" role (full CRUD access to all columns) and "anonymous" role (select only, with sensitive columns like email and password excluded). You should customize these for your application security model, adding row-level check constraints and column restrictions.
Is my SQL data sent to a server?
No. All parsing and code generation runs entirely in your browser. Your SQL schema is never transmitted over the network, and no external services are contacted during the conversion process.
Real-world Examples
Instant GraphQL API for existing database
A team with an existing PostgreSQL database uses this converter to generate Hasura metadata, applies it with hasura metadata apply, and immediately gets a working GraphQL API. The auto-generated relationships let frontend developers query nested data like users with their posts in a single request.
CREATE TABLE categories ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, slug VARCHAR(100) UNIQUE NOT NULL ); CREATE TABLE products ( id SERIAL PRIMARY KEY, category_id INTEGER REFERENCES categories(id), name VARCHAR(200) NOT NULL, price NUMERIC(10,2) NOT NULL );
Object relationship: products.category -> Category Array relationship: categories.products -> [Product] Select permissions: user (all columns), anonymous (excludes slug)
Multi-tenant SaaS with row-level security
A SaaS platform uses the generated metadata as a starting point, then adds custom check constraints to the user role permissions that filter rows by tenant_id from Hasura session variables, ensuring each tenant can only access their own data.