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

To run with PostgreSQL, in MVC tutorial the column year in table movies should not have a limit #502

Open
UniqueTokens opened this issue Mar 18, 2022 · 0 comments
Labels

Comments

@UniqueTokens
Copy link
Contributor

Following Developing MVC web applications tutorial with PostgreSQL instead of SQLite adapter. The column year in table movies should not have a limit to run PostgreSQL migration without errors:

# db/migrations/*_create_table_movies.jl

module CreateTableMovies

import SearchLight.Migrations: create_table, column, primary_key, add_index, drop_table

function up()
  create_table(:movies) do
    [
      primary_key()
      column(:type, :string, limit = 10)
      column(:title, :string, limit = 100)
      column(:directors, :string, limit = 100)
      column(:actors, :string, limit = 250)
      column(:country, :string, limit = 100)
      column(:year, :integer, limit = 4)         # Why limiting an integer field?
      column(:rating, :string, limit = 10)
      column(:categories, :string, limit = 100)
      column(:description, :string, limit = 1_000)
    ]
  end

  add_index(:movies, :title)
  add_index(:movies, :actors)
  add_index(:movies, :categories)
  add_index(:movies, :description)
end

function down()
  drop_table(:movies)
end

end
julia> SearchLight.Migration.last_up()
[ Info: 2022-03-18 20:22:27 SELECT version FROM schema_migrations ORDER BY version DESC
[ Info: 2022-03-18 20:22:27 CREATE TABLE movies (id SERIAL  PRIMARY KEY  , type VARCHAR (10), title VARCHAR (100), directors VARCHAR (100), actors VARCHAR (250), country VARCHAR (100), year BIGINT (4), rating VARCHAR (10), categories VARCHAR (100), description VARCHAR (1000))
[error | LibPQ]: SyntaxError: ERROR:  syntax error at or near "("
LINE 1: ...VARCHAR (250), country VARCHAR (100), year BIGINT (4), ratin...
                                                             ^
┌ Error: 2022-03-18 20:22:27 Failed executing migration CreateTableMovies up
└ @ SearchLight.Migration ~/.julia/packages/SearchLight/T30SB/src/Migration.jl:298
ERROR: SyntaxError: ERROR:  syntax error at or near "("
LINE 1: ...VARCHAR (250), country VARCHAR (100), year BIGINT (4), ratin...
                                                             ^
Stacktrace:
  [1] error(logger::Memento.Logger, exc::LibPQ.Errors.PQResultError{LibPQ.Errors.C42, LibPQ.Errors.E42601})
    @ Memento ~/.julia/packages/Memento/Qk5GZ/src/loggers.jl:458
  [2] handle_result(jl_result::LibPQ.Result{false}; throw_error::Bool)
    @ LibPQ ~/.julia/packages/LibPQ/qB2gf/src/results.jl:238
  [3] _multi_execute(jl_conn::LibPQ.Connection, query::String; throw_error::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ LibPQ ~/.julia/packages/LibPQ/qB2gf/src/results.jl:299
  [4] _multi_execute
    @ ~/.julia/packages/LibPQ/qB2gf/src/results.jl:295 [inlined]
  [5] #execute#51
    @ ~/.julia/packages/LibPQ/qB2gf/src/results.jl:288 [inlined]
  [6] execute
    @ ~/.julia/packages/LibPQ/qB2gf/src/results.jl:285 [inlined]
  [7] query(sql::String, conn::LibPQ.Connection)
    @ SearchLightPostgreSQL ~/.julia/packages/SearchLightPostgreSQL/Uxp6O/src/SearchLightPostgreSQL.jl:134
  [8] query
    @ ~/.julia/packages/SearchLightPostgreSQL/Uxp6O/src/SearchLightPostgreSQL.jl:133 [inlined]
  [9] create_table(f::Function, name::Symbol, options::String) (repeats 2 times)
    @ SearchLightPostgreSQL ~/.julia/packages/SearchLightPostgreSQL/Uxp6O/src/SearchLightPostgreSQL.jl:311
 [10] up()
    @ SearchLight.Migration.CreateTableMovies ~/JuliaProjects/tutorials/genie-watch-tonight-PostgreSQL/Watchtonight/db/migrations/2022031819191178_create_table_movies.jl:6
 [11] #invokelatest#2
    @ ./essentials.jl:716 [inlined]
 [12] invokelatest
    @ ./essentials.jl:714 [inlined]
 [13] run_migration(migration::SearchLight.Migration.DatabaseMigration, direction::Symbol; force::Bool)
    @ SearchLight.Migration ~/.julia/packages/SearchLight/T30SB/src/Migration.jl:292
 [14] #last_up#11
    @ ~/.julia/packages/SearchLight/T30SB/src/Migration.jl:153 [inlined]
 [15] last_up()
    @ SearchLight.Migration ~/.julia/packages/SearchLight/T30SB/src/Migration.jl:153
 [16] top-level scope
    @ REPL[12]:1

After column(:year, :integer, limit = 4) is changed to column(:year, :integer)

julia> SearchLight.Migration.last_up()
[ Info: 2022-03-18 20:23:54 SELECT version FROM schema_migrations ORDER BY version DESC
WARNING: replacing module CreateTableMovies.
[ Info: 2022-03-18 20:23:54 CREATE TABLE movies (id SERIAL  PRIMARY KEY  , type VARCHAR (10), title VARCHAR (100), directors VARCHAR (100), actors VARCHAR (250), country VARCHAR (100), year BIGINT , rating VARCHAR (10), categories VARCHAR (100), description VARCHAR (1000))
[ Info: 2022-03-18 20:23:54 CREATE  INDEX movies__idx_title ON movies (title)
[ Info: 2022-03-18 20:23:54 CREATE  INDEX movies__idx_actors ON movies (actors)
[ Info: 2022-03-18 20:23:54 CREATE  INDEX movies__idx_categories ON movies (categories)
[ Info: 2022-03-18 20:23:54 CREATE  INDEX movies__idx_description ON movies (description)
[ Info: 2022-03-18 20:23:54 INSERT INTO schema_migrations VALUES ('2022031819191178')
[ Info: 2022-03-18 20:23:54 Executed migration CreateTableMovies up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants