Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/2802 support for mysql invisible attribute #3140

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

yoavweber
Copy link

Description

This pull request fixes Issue #2802 by supporting the INVISIBLE column attribute in MySQL.

Main Changes

  • Adjust the parseExtra to support mul multiple attribute values in "extra" column using regex
  • Adjusting inspect to support invisible attribute
  • Adjusting migrate and sqlspec to support invisible attribute
  • Adjusting and adding relevant test

How to Test

  1. Create a Docker Compose File

    In the root directory of your project, create a docker-compose.yml file with the following content:

    version: '3.8'
    
    services:
      mysql:
        image: mysql:8.0
        container_name: mysql_atlas_bug_test
        restart: unless-stopped
        environment:
          MYSQL_ROOT_PASSWORD: rootpassword
          MYSQL_DATABASE: atlas_bug_test
          MYSQL_USER: testuser
          MYSQL_PASSWORD: testpassword
        ports:
          - "3306:3306"
        volumes:
          - ./mysql/init:/docker-entrypoint-initdb.d
          - mysql_data:/var/lib/mysql
        command: --default-authentication-plugin=mysql_native_password
    
    volumes:
      mysql_data:
  2. Add the Schema

    In the root directory, create a folder named mysql/init and add a SQL file (e.g., init.sql) with the following content:

    USE atlas_bug_test;
    
    CREATE TABLE users (
        id INT AUTO_INCREMENT PRIMARY KEY,
        username VARCHAR(50) NOT NULL,
        email VARCHAR(100) NOT NULL,
        email_length INT GENERATED ALWAYS AS (CHAR_LENGTH(email)) STORED INVISIBLE
    );
  3. Compile the Code

    Compile your Atlas project to ensure all changes are built.

  4. Run the Inspection Command

    Execute the following command to inspect the schema:

    atlas schema inspect --url mysql://testuser:testpassword@localhost:3306/atlas_bug_test > schema.atlas

@yoavweber yoavweber changed the title Fix/2802 mysql invisible attribute Fix/2802 support for mysql invisible attribute Sep 23, 2024
@calmdev
Copy link

calmdev commented Sep 28, 2024

I was running into this issue on four different MySQL databases.

Building against this branch I was able to process those tables and no longer encounter the error:

mysql: unknown extra column attribute "DEFAULT_GENERATED INVISIBLE"

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.

Unable to handle mysql column with INVISIBLE attribute
2 participants