PNixx / clickhouse-activerecord

A Ruby database ActiveRecord driver for ClickHouse
MIT License
202 stars 100 forks source link

Missing `schema_migrations` table in schema dump #138

Open svevang opened 5 months ago

svevang commented 5 months ago

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 commented 2 months ago

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 commented 1 month ago

@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 ?