I currently have my Rails 3.2 environment connected with an already existing database, with the oracle_enhanced-adapter handling the connection. What I need to do now is take the already existing tables (which probably aren't in ActiveRecord format) and generate models, controllers, and views for them. However, I'm not sure how to go about creating these. Do I need to do it manually?
As an example, here's the device table in my database:
Device_Name, VARCHAR2(32 BYTE), primary key
Device_Desc, VARCHAR2(400 BYTE)
Created_By, VARCHAR2(8 BYTE)
Creation_Date, DATE
Last_Updated_By, VARCHAR2(8 BYTE)
Last_Updated_Date, DATE
How would I get a controller, model, and view for this in rails. Do I need to manually create the model? Or is this all I would need:
class Device < ActiveRecord::Base
self.table_name="Device"
self.primary_key="Device_Name"
end
Thanks for your help!
Related
I have a table that I created using
CREATE TABLE `digiid_callback` ( `nonce` BINARY(8) NOT NULL, `address` BINARY(20), `expire` TIMESTAMP NOT NULL, PRIMARY KEY (`nonce`) )
So it has 3 fields. 1 is a timestamp and the other 2 hold a small binary data filed.
I am new to working with the yii framework and was wondering what the proper way to create an ActiveRecord for this table would be.
Normally if I was trying to select data from a table like this I would use
SELECT * FROM tablename WHERE nonce=UNHEX(?) LIMIT 1;
the yii equivalent seems to be ObjectName::findOne(?); but I don't know how to add the UNHEX which is needed.
First create DB table, then generate ActiveRecord (AR) class for that table using gii tool and then learn AR tutorial.
I have 1 table moviesfrom csv file. I need to make data warehouse with additional tables genres, production_companies, directors.
For start I want to make new table genres that will have 2083 records.
If I use sequence_name.nextval() than I will have duplicates as I have 10856 movies in movies table.
I will also need to have only genres_id in the table dw_movies, not the genres_name
Please, give me your advise.
Here is movies table:
CREATE TABLE "AS6400U"."MOVIES" (
"ID" NUMBER(38,0),
"IMDB_ID" VARCHAR2(26 BYTE),
"POPULARITY" NUMBER(38,6),
"BUDGET" NUMBER(38,0),
"REVENUE" NUMBER(38,0),
"ORIGINAL_TITLE" VARCHAR2(500 BYTE),
"CAST" VARCHAR2(500 BYTE),
"HOMEPAGE" VARCHAR2(300 BYTE),
"DIRECTOR" VARCHAR2(600 BYTE),
"TAGLINE" VARCHAR2(400 BYTE),
"KEYWORDS" VARCHAR2(500 BYTE),
"OVERVIEW" VARCHAR2(2000 BYTE),
"RUNTIME" NUMBER(38,0),
"GENRES" VARCHAR2(400 BYTE),
"PRODUCTION_COMPANIES" VARCHAR2(500 BYTE),
"RELEASE_DATE" DATE,
"VOTE_COUNT" NUMBER(38,0),
"VOTE_AVERAGE" NUMBER(38,1),
"RELEASE_YEAR" NUMBER(38,0),
"BUDGET_ADJ" NUMBER(38,3),
"REVENUE_ADJ" NUMBER(38,5)
)
Kind regards,
Anna
This is about database modelling. Tables usually depend on each other, and that relationship is maintained through foreign key constraints. Furthermore, tables should be normalized (up to 3rd normal form) so that you wouldn't store the same data twice (or more times).
However, data warehouses act differently because they deal with a lot of data so fetching rows from several huge tables takes time, so DW tables aren't always normalized.
Saying that your tables have 10K rows - that's close-to-nothing for Oracle, so I believe that you should do what I mentioned in the first paragraph: normalize tables first, set relationships (primary keys referenced by foreign keys). Write all those CREATE TABLE statements, one-by-one to make sure you're doing it right.
As of the sequence next value: I'd say that you got it wrong. Usually, its (sequences) values are in ascending order. It doesn't matter that current table has 10K rows and you'd want to create a new table with 2K rows; so what? sequence.nextval will probably be 10K-something (if it was used for movies table as well). You shouldn't (and probably won't) get any duplicates.
I'd echo #Littlefoot, with additional observations about your data model.
RELEASE_YEAR a 38-digit number? Really? It should be a DATE, with default values for month,day, and time components. Even if you want to store it as a NUMBER (bad idea), why do you need 38 digits for it?
GENRES shouldn't be there at all. A movie can have multiple genres, so that should be in a 'link' table - a table with one column as an FK back to the PK of MOVIES, and a second as a FK back to the PK of the GENRES table.
Some of the other columns look like they could use the same treatment. Especially CAST and KEYWORD and PRODUCTION_COMPANIES. (The fact that PRODUCTION_COMPANIES is plural is a giveaway).
All of those 38-digit numbers! 38 digits to hold revenue? A producer could only dream of a movie grossing more than the gross domestic product of the entire planet.
You may think of your database as a 'data warehouse', and that may be true for it's usage patterns (or it may not - the term often gets used very loosely to describe just about any database), but as a practical matter its size is barely a blip. You should design all tables to Third Normal Form, and only resort to 'demoralizing' for performance when you discover an actual performance issue that is positively confirmed needing such treatment.
I have to be able to rename the default Spring Session table and found the following configuration options in the spring session documentation.
spring.session.jdbc.schema=classpath:org/springframework/session/jdbc/schema-##platform##.sql # Path to the SQL file to use to initialize the database schema.
spring.session.jdbc.table-name=SPRING_SESSION # Name of database table used to store sessions.
Here is what I am trying to set in application.properties:
spring.session.store-type=jdbc
spring.session.jdbc.table-name: APP_SPR_SESSION
spring.session.jdbc.schema: src/main/resources/appSpringSession.sql
Here are the contents of appSpringSession.sql which is a modified/renamed version of schema-oracle.sql
CREATE TABLE app_app.APP_SPR_SESSION (
PRIMARY_ID CHAR(36) NOT NULL,
SESSION_ID CHAR(36) NOT NULL,
CREATION_TIME NUMBER(19,0) NOT NULL,
LAST_ACCESS_TIME NUMBER(19,0) NOT NULL,
MAX_INACTIVE_INTERVAL NUMBER(10,0) NOT NULL,
EXPIRY_TIME NUMBER(19,0) NOT NULL,
PRINCIPAL_NAME VARCHAR2(100 CHAR),
CONSTRAINT APP_SPR_SESSION_PK PRIMARY KEY (PRIMARY_ID)
);
CREATE UNIQUE INDEX APP_SPR_SESSION_IX1 ON APP_SPR_SESSION (SESSION_ID);
CREATE INDEX APP_SPR_SESSION_IX2 ON APP_SPR_SESSION (EXPIRY_TIME);
CREATE INDEX APP_SPR_SESSION_IX3 ON APP_SPR_SESSION (PRINCIPAL_NAME);
CREATE TABLE app_app.APP_SPR_SESSION_ATTRIBUTES (
SESSION_PRIMARY_ID CHAR(36) NOT NULL,
ATTRIBUTE_NAME VARCHAR2(200 CHAR) NOT NULL,
ATTRIBUTE_BYTES BLOB NOT NULL,
CONSTRAINT APP_SPR_SESSION_ATTRIBUTES_PK PRIMARY KEY
(SESSION_PRIMARY_ID,
ATTRIBUTE_NAME),
CONSTRAINT APP_SPR_SESSION_ATTRIBUTES_FK FOREIGN KEY
(SESSION_PRIMARY_ID)
REFERENCES APP_SPR_SESSION(PRIMARY_ID) ON DELETE CASCADE
);
I have manually added the tables using the above ddl into the Oracle database and every time the app starts it's still looking for SPRING_SESSION table.
Seems like specifying these options has no effect. What am I reading wrong here from the docs?
Also I am using Spring Session 2.0.2 Release and Spring Boot 2.0.1.RELEASE
The reason spring.session.* do not work for you is because your are using #EnableJdbcHttpSession. That means that you are configuring Spring Session explicitly, so Spring Boot backs off with its auto-configuration.
You should remove #EnableJdbcHttpSession and ensure Spring Boot is auto-configuring Spring Session. Additionally, you could also leave spring.session.store-type out, since Spring Boot should be able to deduce which session repository implementation are you using as long as you have only only SessionRepository implementation on the classpath (i.e. you depend only on spring-session-jdbc and no other Spring Session modules).
You can also use #EnableJdbcHttpSession(tableName = "APP_SPR_SESSION")
I have a GTT in my oracle apex application.
CREATE GLOBAL TEMPORARY TABLE "SEARCH"
( "CODE" VARCHAR2(15 BYTE),
"HEAD" VARCHAR2(100 BYTE),
"BRCODE" VARCHAR2(3 BYTE)
) ON COMMIT PRESERVE ROWS ;
But the GTT preserves it's rows even after the user log out from the application. If another user login to the application, he can access the same data created by the previous user. What might be the problem with GTT or session ?
Please read this answer thread from oracle community. GTT - Global Temporary Table - Problem with Apex
I am creating a Asp.Net site which will accept users' registration/logon. The Asp.Net MVC automatically generate the following tables in a database with a strange name of aspnet-MyProjectName-20120705215524.
Is it possible to let Asp.Net Mvc generate the tables in my own database? (I have other tables which will refer the Users table). I will need the more columns in the table Users. Can I just manually add the columns to it? And I also want the extra columns show in the registration page.
Update
What's the best practice of integrating the system generated Users tables?
Memberships
Profiles
Roles
Users
UsersInRoles
CREATE TABLE [dbo].[Users] (
[ApplicationId] UNIQUEIDENTIFIER NOT NULL,
[UserId] UNIQUEIDENTIFIER NOT NULL,
[UserName] NVARCHAR (50) NOT NULL,
[IsAnonymous] BIT NOT NULL,
[LastActivityDate] DATETIME NOT NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC),
CONSTRAINT [UserApplication] FOREIGN KEY ([ApplicationId]) REFERENCES [dbo].[Applications] ([ApplicationId])
);
Try the aspnet_regsql.exe tool this will generate the application services database for you
http://msdn.microsoft.com/en-us/library/ms229862(v=vs.80).aspx
You could add columns to the default database but I'm not on the effects of that, most of the app services use stored procedures so you could extend them