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

Missing schema_migrations table in schema dump #138

Open
svevang opened this issue Jun 10, 2024 · 3 comments
Open

Missing schema_migrations table in schema dump #138

svevang opened this issue Jun 10, 2024 · 3 comments

Comments

@svevang
Copy link

svevang commented Jun 10, 2024

Version: clickhouse-activerecord (1.0.9)
Rails: 7.1

I have a rails app with config.active_record.schema_format = :sql. When I run the db:schema:dump command the schema_migrations table is being ignored and does not end up in the db/clickhouse_structure.sql file.

The migrations versions are considered part of the schema dump. And I do end up with statements appended to the end of the file that look like:

-- create some tables etc

-- at the end of the db/clickhouse_structure.sql file, are the AR schema migration inserts:
INSERT INTO schema_migrations (version) VALUES
('20240603201007');

However, because the schema_migrations table is not preset in the structure file, when I do something like RAILS_ENV=test ./bin/rails db:create db:prepare these insert statements produce an error, because the schema_migrations table is not present.

Compared to the PostgreSQL adapter (for example), there is a schema_migrations table in the structure dump that looks like:

--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
--
  
CREATE TABLE public.schema_migrations (
    version character varying NOT NULL
);
@woodhull
Copy link

woodhull commented Sep 6, 2024

The schema_migrations table is suppressed from the dump in

https://github.com/PNixx/clickhouse-activerecord/blame/246775c0475cd309e5a03238235cc31b68f6516c/lib/clickhouse-activerecord/tasks.rb#L42

I do not understand the intent of doing that.

@kirsha2
Copy link

kirsha2 commented Oct 15, 2024

@woodhull thanks for the link ! that's gonna be ez monkey patch :D for me

@PNixx can you maybe explain why schema_migrations ar_internal_metadata are not dumped in the structure ?

@leboshi
Copy link
Contributor

leboshi commented Dec 3, 2024

@PNixx I think I understand the rationale behind not locking the implementation of schema_migrations and ar_internal_metadata into a SQL dump. But since that change was made, would it make sense instead to make sure db:create creates those tables? We did this on our main branch. I can make a separate PR for this if this is a solution you like.

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

No branches or pull requests

4 participants